Skip to content

Commit a4c5ed8

Browse files
author
Alexander Zvegintsev
committed
8354561: Open source several swing tests batch0
Reviewed-by: prr, psadhukhan
1 parent da16c83 commit a4c5ed8

File tree

4 files changed

+397
-0
lines changed

4 files changed

+397
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4139900
27+
* @summary height of combobox may differ
28+
* @key headful
29+
* @run main bug4139900
30+
*/
31+
32+
import java.awt.Dimension;
33+
import java.awt.Robot;
34+
import java.awt.event.ActionListener;
35+
import javax.swing.DefaultComboBoxModel;
36+
import javax.swing.JButton;
37+
import javax.swing.JComboBox;
38+
import javax.swing.JFrame;
39+
import javax.swing.JPanel;
40+
import javax.swing.SwingUtilities;
41+
42+
public class bug4139900 {
43+
static JButton button;
44+
static JFrame frame;
45+
static JComboBox<String> comboBox;
46+
static int initialHeight;
47+
48+
public static void main(String[] args) throws Exception {
49+
try {
50+
SwingUtilities.invokeAndWait(bug4139900::init);
51+
test();
52+
} finally {
53+
SwingUtilities.invokeAndWait(() -> {
54+
if (frame != null) {
55+
frame.dispose();
56+
}
57+
});
58+
}
59+
}
60+
61+
private static void test() throws Exception {
62+
Robot robot = new Robot();
63+
robot.waitForIdle();
64+
robot.delay(500);
65+
66+
SwingUtilities.invokeAndWait(() -> initialHeight = comboBox.getHeight());
67+
68+
for (int i = 0; i < 10; i++) {
69+
SwingUtilities.invokeAndWait(() -> button.doClick());
70+
robot.waitForIdle();
71+
robot.delay(200);
72+
SwingUtilities.invokeAndWait(() -> {
73+
if (comboBox.getHeight() != initialHeight) {
74+
throw new RuntimeException(
75+
"Test failed: height differs from initial %d != %d"
76+
.formatted(comboBox.getHeight(), initialHeight)
77+
);
78+
}
79+
});
80+
}
81+
}
82+
83+
public static void init() {
84+
frame = new JFrame("bug4139900");
85+
86+
DefaultComboBoxModel<String> model =
87+
new DefaultComboBoxModel<>(new String[]{
88+
"Coma Berenices",
89+
"Triangulum",
90+
"Camelopardis",
91+
"Cassiopea"
92+
});
93+
94+
comboBox = new JComboBox<>();
95+
comboBox.setEditable(true);
96+
97+
button = new JButton("Add/Remove Items");
98+
99+
ActionListener actionListener = e -> {
100+
if (comboBox.getModel() == model) {
101+
comboBox.setModel(new DefaultComboBoxModel<>());
102+
} else {
103+
comboBox.setModel(model);
104+
}
105+
};
106+
107+
button.addActionListener(actionListener);
108+
109+
JPanel panel = new JPanel();
110+
panel.setPreferredSize(new Dimension(300, 100));
111+
panel.add(comboBox);
112+
panel.add(button);
113+
114+
frame.add(panel);
115+
frame.pack();
116+
frame.setLocationRelativeTo(null);
117+
frame.setVisible(true);
118+
}
119+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4174876
27+
* @summary JComboBox tooltips do not work properly
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4174876
31+
*/
32+
33+
import javax.swing.JComboBox;
34+
import javax.swing.JComponent;
35+
import javax.swing.JPanel;
36+
37+
public class bug4174876 {
38+
private static final String INSTRUCTIONS = """
39+
Hold the mouse over both combo boxes.
40+
A tool tip should appear over every area of both of them.
41+
Notably, if you hold the mouse over the button on the right one,
42+
a tool tip should appear.
43+
""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("TransparentTitleTest Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.columns(40)
50+
.splitUIBottom(bug4174876::createTestUI)
51+
.build()
52+
.awaitAndCheck();
53+
}
54+
55+
private static JComponent createTestUI() {
56+
JComboBox<String> comboBox1 = new JComboBox<>(new String[]{
57+
"Coma Berenices",
58+
"Triangulum",
59+
"Camelopardis",
60+
"Cassiopea"
61+
});
62+
JComboBox<String> comboBox2 = new JComboBox<>(new String[]{
63+
"Coma Berenices",
64+
"Triangulum",
65+
"Camelopardis",
66+
"Cassiopea"
67+
});
68+
69+
comboBox1.setToolTipText("Combo Box #1");
70+
comboBox2.setToolTipText("Combo Box #2");
71+
comboBox2.setEditable(true);
72+
73+
JPanel panel = new JPanel();
74+
panel.add(comboBox1);
75+
panel.add(comboBox2);
76+
return panel;
77+
}
78+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
/*
25+
* @test
26+
* @bug 4474400
27+
* @summary Tests JTextArea wrapping with font change
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4474400
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Dimension;
35+
import java.awt.Font;
36+
import javax.swing.JButton;
37+
import javax.swing.JComponent;
38+
import javax.swing.JPanel;
39+
import javax.swing.JTextArea;
40+
41+
public class bug4474400 {
42+
private static final String INSTRUCTIONS = """
43+
Press the "Change Font" button. The two lines of text should be
44+
properly drawn using the larger font, there should be empty line
45+
between them. If display is garbled, test fails.
46+
""";
47+
48+
public static void main(String[] args) throws Exception {
49+
PassFailJFrame.builder()
50+
.title("bug4474400 Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.columns(40)
53+
.splitUIRight(bug4474400::createTestUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
private static JComponent createTestUI() {
59+
Font smallFont = new Font("SansSerif", Font.PLAIN, 12);
60+
Font largeFont = new Font("SansSerif", Font.PLAIN, 36);
61+
62+
JTextArea textArea = new JTextArea("This is the first line\n\nThis is the third line");
63+
textArea.setFont(smallFont);
64+
textArea.setEditable(false);
65+
textArea.setLineWrap(true);
66+
textArea.setWrapStyleWord(true);
67+
68+
JButton b = new JButton("Change Font");
69+
b.addActionListener((e) -> textArea.setFont(largeFont));
70+
71+
JPanel panel = new JPanel(new BorderLayout());
72+
panel.setPreferredSize(new Dimension(200, 300));
73+
panel.add(textArea, BorderLayout.CENTER);
74+
panel.add(b, BorderLayout.SOUTH);
75+
76+
return panel;
77+
}
78+
}

0 commit comments

Comments
 (0)