43
43
import javax .swing .JRadioButton ;
44
44
import javax .swing .SwingUtilities ;
45
45
import javax .swing .UIManager ;
46
+ import javax .swing .UnsupportedLookAndFeelException ;
46
47
47
48
public class bug8033699 {
48
-
49
49
private static JFrame mainFrame ;
50
50
private static Robot robot ;
51
51
private static JButton btnStart ;
@@ -57,64 +57,80 @@ public class bug8033699 {
57
57
private static JRadioButton radioBtnSingle ;
58
58
59
59
public static void main (String [] args ) throws Throwable {
60
- SwingUtilities .invokeAndWait (() -> {
61
- changeLAF ();
62
- createAndShowGUI ();
63
- });
64
-
65
60
robot = new Robot ();
66
- robot .waitForIdle ();
67
- robot .delay (1000 );
68
-
69
- // tab key test grouped radio button
70
- runTest1 ();
71
- robot .delay (100 );
72
-
73
- // tab key test non-grouped radio button
74
- runTest2 ();
75
- robot .delay (100 );
76
-
77
- // shift tab key test grouped and non-grouped radio button
78
- runTest3 ();
79
- robot .delay (100 );
80
-
81
- // left/up key test in grouped radio button
82
- runTest4 ();
83
- robot .delay (100 );
84
61
85
- // down/right key test in grouped radio button
86
- runTest5 ();
87
- robot .delay (100 );
88
-
89
- // tab from radio button in group to next component in the middle of button group layout
90
- runTest6 ();
91
- robot .delay (100 );
92
-
93
- // tab to radio button in group from component in the middle of button group layout
94
- runTest7 ();
95
- robot .delay (100 );
96
-
97
- // down key circle back to first button in grouped radio button
98
- runTest8 ();
99
- robot .delay (100 );
100
-
101
- // Verify that ActionListener is called when a RadioButton is selected using arrow key.
102
- runTest9 ();
103
- robot .delay (100 );
62
+ // Get all installed Look and Feels
63
+ UIManager .LookAndFeelInfo [] lafs = UIManager .getInstalledLookAndFeels ();
64
+ for (UIManager .LookAndFeelInfo laf : lafs ) {
65
+ testLaF (laf );
66
+ }
67
+ }
104
68
105
- SwingUtilities .invokeAndWait (() -> mainFrame .dispose ());
69
+ private static void testLaF (UIManager .LookAndFeelInfo laf ) throws Exception {
70
+ try {
71
+ System .out .println ("Testing LaF: " + laf .getName ());
72
+ SwingUtilities .invokeAndWait (() -> {
73
+ setLookAndFeel (laf );
74
+ createAndShowGUI ();
75
+ });
76
+
77
+ robot .waitForIdle ();
78
+ robot .delay (1000 );
79
+
80
+ // tab key test grouped radio button
81
+ runTest1 ();
82
+ robot .delay (100 );
83
+
84
+ // tab key test non-grouped radio button
85
+ runTest2 ();
86
+ robot .delay (100 );
87
+
88
+ // shift tab key test grouped and non-grouped radio button
89
+ runTest3 ();
90
+ robot .delay (100 );
91
+
92
+ // left/up key test in grouped radio button
93
+ runTest4 ();
94
+ robot .delay (100 );
95
+
96
+ // down/right key test in grouped radio button
97
+ runTest5 ();
98
+ robot .delay (100 );
99
+
100
+ // tab from radio button in group to next component in the middle of button group layout
101
+ runTest6 ();
102
+ robot .delay (100 );
103
+
104
+ // tab to radio button in group from component in the middle of button group layout
105
+ runTest7 ();
106
+ robot .delay (100 );
107
+
108
+ // down key circle back to first button in grouped radio button
109
+ runTest8 ();
110
+ robot .delay (100 );
111
+
112
+ // Verify that ActionListener is called when a RadioButton is selected using arrow key.
113
+ runTest9 ();
114
+ robot .delay (100 );
115
+ } catch (Exception e ) {
116
+ throw new RuntimeException ("Error testing LaF: " + laf .getName (), e );
117
+ } finally {
118
+ SwingUtilities .invokeAndWait (() -> {
119
+ if (mainFrame != null ) {
120
+ mainFrame .dispose ();
121
+ mainFrame = null ;
122
+ }
123
+ });
124
+ }
106
125
}
107
126
108
- private static void changeLAF () {
109
- String currentLAF = UIManager .getLookAndFeel ().toString ();
110
- System .out .println (currentLAF );
111
- currentLAF = currentLAF .toLowerCase ();
112
- if (currentLAF .contains ("nimbus" )) {
113
- try {
114
- UIManager .setLookAndFeel ("javax.swing.plaf.metal.MetalLookAndFeel" );
115
- } catch (Exception ex ) {
116
- ex .printStackTrace ();
117
- }
127
+ private static void setLookAndFeel (UIManager .LookAndFeelInfo laf ) {
128
+ try {
129
+ UIManager .setLookAndFeel (laf .getClassName ());
130
+ } catch (ClassNotFoundException | InstantiationException |
131
+ IllegalAccessException | UnsupportedLookAndFeelException e ) {
132
+ System .err .println ("Error setting LaF: " + laf .getName ());
133
+ throw new RuntimeException ("Failed to set look and feel" , e );
118
134
}
119
135
}
120
136
0 commit comments