1
+ /*
2
+ * Copyright (c) 2022, 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 8054572
27
+ * @library /java/awt/regtesthelpers
28
+ * @build PassFailJFrame
29
+ * @summary Tests if JComboBox displays correctly when editable/non-editable
30
+ * @run main/manual JComboBoxBorderTest
31
+ */
32
+
33
+ import java .awt .FlowLayout ;
34
+ import java .lang .reflect .InvocationTargetException ;
35
+
36
+ import javax .swing .JComboBox ;
37
+ import javax .swing .JFrame ;
38
+ import javax .swing .JLabel ;
39
+ import javax .swing .JPanel ;
40
+ import javax .swing .SwingUtilities ;
41
+ import javax .swing .UIManager ;
42
+
43
+ public class JComboBoxBorderTest {
44
+ private static final String instructionsText = "Pass if you can see both " +
45
+ "an editable and non-editable JComboBox and if they display " +
46
+ "reasonably. Fail if they do not appear or are misaligned." ;
47
+
48
+ private static JFrame frame ;
49
+
50
+ public static void createAndShowGUI () throws InterruptedException ,
51
+ InvocationTargetException {
52
+ SwingUtilities .invokeAndWait (() -> {
53
+
54
+ JLabel label = new JLabel ("Editable combo box:" );
55
+ JLabel label2 = new JLabel ("Non-editable combo box:" );
56
+
57
+ JComboBox <String > comboBox = new JComboBox <>(new String []
58
+ { "Item 1" , "Item 2" , "Item 3" });
59
+ JComboBox <String > comboBox2 = new JComboBox <>(new String []
60
+ { "Item 1" , "Item 2" , "Item 3" });
61
+ comboBox .setEditable (true );
62
+
63
+ FlowLayout layout = new FlowLayout (FlowLayout .LEADING );
64
+ JPanel panel = new JPanel (layout );
65
+ panel .add (label );
66
+ panel .add (comboBox );
67
+
68
+ panel .add (label2 );
69
+ panel .add (comboBox2 );
70
+
71
+ frame = new JFrame ();
72
+ frame .getContentPane ().add (panel );
73
+ frame .pack ();
74
+ frame .setLocationRelativeTo (null );
75
+
76
+ PassFailJFrame .addTestWindow (frame );
77
+ PassFailJFrame .positionTestWindow (frame ,
78
+ PassFailJFrame .Position .HORIZONTAL );
79
+
80
+ frame .setVisible (true );
81
+ });
82
+ }
83
+
84
+ public static void main (String [] args ) throws Exception {
85
+
86
+ UIManager .setLookAndFeel ("com.apple.laf.AquaLookAndFeel" );
87
+
88
+ PassFailJFrame pfjFrame = new PassFailJFrame ("JScrollPane "
89
+ + "Test Instructions" , instructionsText , 5 );
90
+
91
+ createAndShowGUI ();
92
+
93
+ pfjFrame .awaitAndCheck ();
94
+ }
95
+ }
0 commit comments