11/*
2- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
24- /*
25- * @test
26- * @bug 4319113
27- * @summary Tests the open JColorChooser behavior on LaF change.
28- * @author yan
29- * @run applet/manual=yesno Test4319113.html
30- */
31-
32-
3324import java .awt .Color ;
3425import java .awt .Component ;
3526import java .awt .Frame ;
3627import java .awt .GridLayout ;
37- import java .awt .LayoutManager ;
3828import java .awt .Window ;
3929import java .awt .event .ActionEvent ;
4030import java .awt .event .ActionListener ;
4131import java .awt .event .ItemEvent ;
4232import java .awt .event .ItemListener ;
43- import java .io .PrintStream ;
44- import javax .swing .JApplet ;
4533import javax .swing .JButton ;
4634import javax .swing .JColorChooser ;
4735import javax .swing .JComboBox ;
5038import javax .swing .SwingUtilities ;
5139import javax .swing .UIManager ;
5240
53- public class Test4319113
54- extends JApplet
55- implements ActionListener {
56- private final JFrame frame = new JFrame ("frame" );
57- private JComboBox cbPlaf ;
41+ /*
42+ * @test
43+ * @bug 4319113
44+ * @library /java/awt/regtesthelpers
45+ * @build PassFailJFrame
46+ * @summary Tests the open JColorChooser behavior on LaF change.
47+ * @run main/manual Test4319113
48+ */
49+ public class Test4319113 {
5850
59- @ Override
60- public void init () {
61- try {
62- java .awt .EventQueue .invokeLater ( () -> {
63- Test4319113 .this .frame .setLayout (new GridLayout (2 , 1 ));
64- Test4319113 .this .show (Test4319113 .this .frame );
65- });
66- }catch (Exception ex ) {
67- ex .printStackTrace ();
68- }
69- }
51+ public static void main (String [] args ) throws Exception {
52+ String instructions = "1. Press button \" Show ColorChooser\" in the frame \" frame\" and\n " +
53+ " a color chooser dialog should appear.\n " +
54+ "2. Without closing the color chooser, change Look And Feel\n " +
55+ " selecting it from the combobox in the frame \" frame\" .\n " +
56+ " Dialog appearance will change.\n " +
57+ "3. Resize the color chooser by mouse drag.\n " +
58+ "\n " +
59+ " If you see some remnants of the previous color chooser,\n " +
60+ " press \" Fail\" else press \" Pass\" ." ;
7061
71- @ Override
72- public void actionPerformed (ActionEvent actionEvent ) {
73- Object object = actionEvent .getSource ();
74- Component component = object instanceof Component ? (Component )object : null ;
75- JDialog jDialog = JColorChooser .createDialog (component , "ColorChooser" , false , new JColorChooser (Color .BLUE ), null , null );
76- jDialog .setVisible (true );
62+ PassFailJFrame .builder ()
63+ .title ("Test4319113" )
64+ .instructions (instructions )
65+ .rows (5 )
66+ .columns (40 )
67+ .testTimeOut (10 )
68+ .testUI (Test4319113 ::test )
69+ .build ()
70+ .awaitAndCheck ();
7771 }
7872
79- private void show (Window window ) {
73+ private static JFrame test () {
74+ JFrame frame = new JFrame ("JColorChooser behavior on LaF change" );
75+ frame .setLayout (new GridLayout (2 , 1 ));
76+
8077 JButton jButton = new JButton ("Show ColorChooser" );
8178 jButton .setActionCommand ("Show ColorChooser" );
82- jButton .addActionListener (this );
83- this .cbPlaf = new JComboBox <UIManager .LookAndFeelInfo >(UIManager .getInstalledLookAndFeels ());
84- this .cbPlaf .addItemListener (new ItemListener (){
79+ jButton .addActionListener (new ActionListener () {
80+ @ Override
81+ public void actionPerformed (ActionEvent actionEvent ) {
82+ Object object = actionEvent .getSource ();
83+ Component component = object instanceof Component ? (Component ) object : null ;
84+ JDialog jDialog = JColorChooser .createDialog (component , "ColorChooser" ,
85+ false , new JColorChooser (Color .BLUE ), null , null );
86+ jDialog .setVisible (true );
87+ }
88+ });
8589
90+ JComboBox cbPlaf = new JComboBox <UIManager .LookAndFeelInfo >(UIManager .getInstalledLookAndFeels ());
91+ cbPlaf .addItemListener (new ItemListener () {
8692 @ Override
8793 public void itemStateChanged (ItemEvent itemEvent ) {
8894 if (itemEvent .getStateChange () == 1 ) {
89- SwingUtilities .invokeLater (new Runnable (){
95+ SwingUtilities .invokeLater (new Runnable () {
9096
9197 @ Override
9298 public void run () {
93- UIManager .LookAndFeelInfo lookAndFeelInfo = (UIManager .LookAndFeelInfo )Test4319113 .this .cbPlaf .getSelectedItem ();
99+ UIManager .LookAndFeelInfo lookAndFeelInfo =
100+ (UIManager .LookAndFeelInfo ) cbPlaf .getSelectedItem ();
94101 try {
95102 UIManager .setLookAndFeel (lookAndFeelInfo .getClassName ());
96103 Frame [] arrframe = Frame .getFrames ();
97104 int n = arrframe .length ;
98105 while (--n >= 0 ) {
99106 Test4319113 .updateWindowTreeUI (arrframe [n ]);
100107 }
101- }
102- catch (Exception var2_3 ) {
108+ } catch (Exception var2_3 ) {
103109 System .err .println ("Exception while changing L&F!" );
104110 }
105111 }
@@ -108,10 +114,12 @@ public void run() {
108114 }
109115
110116 });
111- window .add (this .cbPlaf );
112- window .add (jButton );
113- window .pack ();
114- window .setVisible (true );
117+
118+ frame .add (cbPlaf );
119+ frame .add (jButton );
120+ frame .pack ();
121+
122+ return frame ;
115123 }
116124
117125 private static void updateWindowTreeUI (Window window ) {
0 commit comments