Skip to content

Commit da16c83

Browse files
author
Alisen Chung
committed
8354466: Open some misc Swing bugs 9
Reviewed-by: kizune, honkar
1 parent 072b827 commit da16c83

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2000, 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+
import java.awt.FlowLayout;
25+
import java.awt.event.ItemListener;
26+
import javax.swing.JCheckBox;
27+
import javax.swing.JFrame;
28+
import javax.swing.JPasswordField;
29+
30+
/*
31+
* @test
32+
* @bug 4382819
33+
* @summary Tests the correctness of color used for the disabled passwordField.
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual bug4382819
37+
*/
38+
39+
public class bug4382819 {
40+
static JCheckBox enabledCheckBox;
41+
static JPasswordField passwordField;
42+
43+
private static final String INSTRUCTIONS = """
44+
Clear the "enabled" checkbox.
45+
If the JPasswordField's foreground color changes to
46+
light gray press Pass. If it stays black press Fail.
47+
""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.instructions(INSTRUCTIONS)
52+
.columns(50)
53+
.testUI(bug4382819::createTestUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
public static JFrame createTestUI() {
59+
JFrame mainFrame = new JFrame("bug4382819");
60+
enabledCheckBox = new javax.swing.JCheckBox();
61+
enabledCheckBox.setSelected(true);
62+
enabledCheckBox.setText("enabled");
63+
enabledCheckBox.setActionCommand("enabled");
64+
mainFrame.add(enabledCheckBox);
65+
66+
passwordField = new javax.swing.JPasswordField();
67+
passwordField.setText("blahblahblah");
68+
mainFrame.add(passwordField);
69+
SymItem lSymItem = new SymItem();
70+
enabledCheckBox.addItemListener(lSymItem);
71+
72+
mainFrame.setSize(300, 100);
73+
mainFrame.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
74+
return mainFrame;
75+
}
76+
77+
static class SymItem implements ItemListener {
78+
public void itemStateChanged(java.awt.event.ItemEvent event) {
79+
Object object = event.getSource();
80+
if (object == enabledCheckBox) {
81+
passwordField.setEnabled(enabledCheckBox.isSelected());
82+
}
83+
}
84+
}
85+
}
86+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2003, 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+
import java.awt.Color;
25+
import java.awt.Dimension;
26+
import java.awt.Panel;
27+
import javax.swing.Box;
28+
import javax.swing.BoxLayout;
29+
import javax.swing.JFrame;
30+
import javax.swing.JPanel;
31+
import javax.swing.JSeparator;
32+
import javax.swing.JSplitPane;
33+
import javax.swing.UIManager;
34+
35+
/*
36+
* @test
37+
* @bug 4820080 7175397
38+
* @summary RFE: Cannot Change the JSplitPane Divider Color while dragging
39+
* @library /java/awt/regtesthelpers
40+
* @build PassFailJFrame
41+
* @run main/manual bug4820080
42+
*/
43+
44+
public class bug4820080 {
45+
private static final String INSTRUCTIONS = """
46+
Drag the dividers of the splitpanes (both top and bottom). If the divider
47+
color is green while dragging then test passes, otherwise test fails.
48+
""";
49+
50+
public static void main(String[] args) throws Exception {
51+
PassFailJFrame.builder()
52+
.instructions(INSTRUCTIONS)
53+
.columns(50)
54+
.testUI(bug4820080::createTestUI)
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
public static JFrame createTestUI() {
60+
JFrame frame = new JFrame("bug4820080");
61+
UIManager.put("SplitPaneDivider.draggingColor", Color.GREEN);
62+
63+
Box box = new Box(BoxLayout.Y_AXIS);
64+
frame.add(box);
65+
66+
JPanel jleft = new JPanel();
67+
jleft.setBackground(Color.DARK_GRAY);
68+
jleft.setPreferredSize(new Dimension(100, 100));
69+
JPanel jright = new JPanel();
70+
jright.setBackground(Color.DARK_GRAY);
71+
jright.setPreferredSize(new Dimension(100, 100));
72+
73+
JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jleft, jright);
74+
jsp.setContinuousLayout(false);
75+
box.add(jsp);
76+
77+
box.add(Box.createVerticalStrut(5));
78+
box.add(new JSeparator());
79+
box.add(Box.createVerticalStrut(5));
80+
81+
Panel left = new Panel();
82+
left.setBackground(Color.DARK_GRAY);
83+
left.setPreferredSize(new Dimension(100, 100));
84+
Panel right = new Panel();
85+
right.setBackground(Color.DARK_GRAY);
86+
right.setPreferredSize(new Dimension(100, 100));
87+
88+
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
89+
sp.setContinuousLayout(false);
90+
box.add(sp);
91+
frame.pack();
92+
return frame;
93+
}
94+
}

0 commit comments

Comments
 (0)