4343import javax .swing .JRadioButton ;
4444import javax .swing .SwingUtilities ;
4545import javax .swing .UIManager ;
46+ import javax .swing .UnsupportedLookAndFeelException ;
4647
4748public class bug8033699 {
48-
4949 private static JFrame mainFrame ;
5050 private static Robot robot ;
5151 private static JButton btnStart ;
@@ -57,64 +57,80 @@ public class bug8033699 {
5757 private static JRadioButton radioBtnSingle ;
5858
5959 public static void main (String [] args ) throws Throwable {
60- SwingUtilities .invokeAndWait (() -> {
61- changeLAF ();
62- createAndShowGUI ();
63- });
64-
6560 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 );
8461
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+ }
10468
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+ }
106125 }
107126
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 );
118134 }
119135 }
120136
0 commit comments