Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java
38854 views
1
/*
2
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4247996 4260485
26
* @summary Test that rollover toolbar doesn't corrupt buttons
27
* @author Peter Zhelezniakov
28
* @run main bug4247996
29
*/
30
import java.awt.*;
31
import javax.swing.*;
32
33
public class bug4247996 {
34
35
private static JButton button;
36
private static JToggleButton toogleButton;
37
38
public static void main(String[] args) throws Exception {
39
40
Robot robot = new Robot();
41
robot.setAutoDelay(50);
42
43
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
44
45
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
46
47
public void run() {
48
createAndShowGUI();
49
}
50
});
51
52
robot.waitForIdle();
53
54
Point point = getButtonCenter();
55
robot.mouseMove(point.x, point.y);
56
robot.waitForIdle();
57
58
checkButtonsSize();
59
60
}
61
62
private static void checkButtonsSize() throws Exception {
63
SwingUtilities.invokeAndWait(new Runnable() {
64
65
@Override
66
public void run() {
67
if (!button.getSize().equals(toogleButton.getSize())) {
68
throw new RuntimeException("Button sizes are different!");
69
}
70
}
71
});
72
}
73
74
private static Point getButtonCenter() throws Exception {
75
final Point[] result = new Point[1];
76
77
SwingUtilities.invokeAndWait(new Runnable() {
78
79
@Override
80
public void run() {
81
Point p = button.getLocationOnScreen();
82
Dimension size = button.getSize();
83
result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2);
84
}
85
});
86
return result[0];
87
}
88
89
private static void createAndShowGUI() {
90
JFrame frame = new JFrame("Test");
91
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
92
frame.setSize(200, 200);
93
94
JButton rButton = new JButton("Rollover");
95
rButton.setRolloverEnabled(true);
96
JToolBar nrToolbar = new JToolBar();
97
nrToolbar.add(rButton);
98
nrToolbar.remove(rButton);
99
100
if (!rButton.isRolloverEnabled()) {
101
throw new Error("Failed (bug 4260485): "
102
+ "toolbar overrode button's rollover property");
103
}
104
105
JToolBar rToolbar = new JToolBar();
106
rToolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
107
rToolbar.add(button = new JButton("Test"));
108
rToolbar.add(toogleButton = new JToggleButton("Test"));
109
110
frame.getContentPane().add(rToolbar, BorderLayout.NORTH);
111
frame.setVisible(true);
112
}
113
}
114
115