1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
21
21
* questions.
22
22
*/
23
23
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
-
33
24
import java .awt .Color ;
34
25
import java .awt .Component ;
35
26
import java .awt .Frame ;
36
27
import java .awt .GridLayout ;
37
- import java .awt .LayoutManager ;
38
28
import java .awt .Window ;
39
29
import java .awt .event .ActionEvent ;
40
30
import java .awt .event .ActionListener ;
41
31
import java .awt .event .ItemEvent ;
42
32
import java .awt .event .ItemListener ;
43
- import java .io .PrintStream ;
44
- import javax .swing .JApplet ;
45
33
import javax .swing .JButton ;
46
34
import javax .swing .JColorChooser ;
47
35
import javax .swing .JComboBox ;
50
38
import javax .swing .SwingUtilities ;
51
39
import javax .swing .UIManager ;
52
40
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 {
58
50
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\" ." ;
70
61
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 ();
77
71
}
78
72
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
+
80
77
JButton jButton = new JButton ("Show ColorChooser" );
81
78
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
+ });
85
89
90
+ JComboBox cbPlaf = new JComboBox <UIManager .LookAndFeelInfo >(UIManager .getInstalledLookAndFeels ());
91
+ cbPlaf .addItemListener (new ItemListener () {
86
92
@ Override
87
93
public void itemStateChanged (ItemEvent itemEvent ) {
88
94
if (itemEvent .getStateChange () == 1 ) {
89
- SwingUtilities .invokeLater (new Runnable (){
95
+ SwingUtilities .invokeLater (new Runnable () {
90
96
91
97
@ Override
92
98
public void run () {
93
- UIManager .LookAndFeelInfo lookAndFeelInfo = (UIManager .LookAndFeelInfo )Test4319113 .this .cbPlaf .getSelectedItem ();
99
+ UIManager .LookAndFeelInfo lookAndFeelInfo =
100
+ (UIManager .LookAndFeelInfo ) cbPlaf .getSelectedItem ();
94
101
try {
95
102
UIManager .setLookAndFeel (lookAndFeelInfo .getClassName ());
96
103
Frame [] arrframe = Frame .getFrames ();
97
104
int n = arrframe .length ;
98
105
while (--n >= 0 ) {
99
106
Test4319113 .updateWindowTreeUI (arrframe [n ]);
100
107
}
101
- }
102
- catch (Exception var2_3 ) {
108
+ } catch (Exception var2_3 ) {
103
109
System .err .println ("Exception while changing L&F!" );
104
110
}
105
111
}
@@ -108,10 +114,12 @@ public void run() {
108
114
}
109
115
110
116
});
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 ;
115
123
}
116
124
117
125
private static void updateWindowTreeUI (Window window ) {
0 commit comments