2121 * questions.
2222 */
2323
24+ import java .io .File ;
25+
26+ import java .awt .image .BufferedImage ;
27+ import java .awt .Dimension ;
2428import java .awt .GridBagConstraints ;
2529import java .awt .GridBagLayout ;
2630import java .awt .Point ;
2731import java .awt .Rectangle ;
2832import java .awt .Robot ;
33+ import java .awt .Toolkit ;
2934import java .awt .event .InputEvent ;
3035
3136import javax .swing .JFrame ;
3843import javax .swing .event .ChangeEvent ;
3944import javax .swing .event .ChangeListener ;
4045
46+ import javax .imageio .ImageIO ;
4147import static javax .swing .UIManager .getInstalledLookAndFeels ;
4248
49+
4350/**
4451 * @test
4552 * @bug 4788637 7124307
@@ -52,22 +59,23 @@ public final class bug4788637 {
5259 private static JFrame fr ;
5360
5461 private static Robot robot ;
55- private int step ;
56- private boolean spinnerValueChanged [] = {false , false , false };
62+ private int step = 0 ;
63+ private volatile boolean spinnerValueChanged [] = {false , false , false };
5764
58- private static Point p ;
59- private static Rectangle rect ;
65+ private static volatile Point p ;
66+ private static volatile Rectangle rect ;
6067
6168 public static void main (final String [] args ) throws Exception {
6269 robot = new Robot ();
63- robot .setAutoDelay (50 );
70+ robot .setAutoDelay (100 );
6471 robot .setAutoWaitForIdle (true );
6572 for (final UIManager .LookAndFeelInfo laf : getInstalledLookAndFeels ()) {
6673 SwingUtilities .invokeAndWait (() -> setLookAndFeel (laf ));
6774 bug4788637 app = new bug4788637 ();
6875 try {
6976 SwingUtilities .invokeAndWait (app ::createAndShowGUI );
7077 robot .waitForIdle ();
78+ robot .delay (1000 );
7179 SwingUtilities .invokeAndWait (()-> {
7280 spinner .requestFocus ();
7381 p = spinner .getLocationOnScreen ();
@@ -106,9 +114,11 @@ public void stateChanged(ChangeEvent e) {
106114 public void start () {
107115 try {
108116 Thread .sleep (1000 );
117+ System .out .println ("p " + p + " rect " + rect );
109118 // Move mouse to the up arrow button
110119 robot .mouseMove (p .x +rect .width -3 , p .y +3 );
111- robot .mousePress (InputEvent .BUTTON1_MASK );
120+ robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
121+
112122 synchronized (bug4788637 .this ) {
113123 if (!spinnerValueChanged [step ]) {
114124 bug4788637 .this .wait (3000 );
@@ -123,6 +133,7 @@ public void start() {
123133 bug4788637 .this .wait (3000 );
124134 }
125135 }
136+ robot .waitForIdle ();
126137
127138 // Move mouse to the up arrow button
128139 robot .mouseMove (p .x +rect .width -3 , p .y +3 );
@@ -132,8 +143,10 @@ public void start() {
132143 bug4788637 .this .wait (3000 );
133144 }
134145 }
146+ robot .waitForIdle ();
135147
136- robot .mouseRelease (InputEvent .BUTTON1_MASK );
148+ robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
149+ robot .waitForIdle ();
137150 } catch (Throwable t ) {
138151 throw new RuntimeException (t );
139152 }
@@ -145,6 +158,15 @@ public void destroy() {
145158 if (!spinnerValueChanged [0 ] ||
146159 spinnerValueChanged [1 ] ||
147160 !spinnerValueChanged [2 ]) {
161+ System .out .println ("!spinnerValueChanged[0] " + !spinnerValueChanged [0 ] +
162+ " spinnerValueChanged[1] " + spinnerValueChanged [1 ] +
163+ " !spinnerValueChanged[2] " + !spinnerValueChanged [2 ]);
164+ try {
165+ Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
166+ Rectangle screen = new Rectangle (0 , 0 , (int ) screenSize .getWidth (), (int ) screenSize .getHeight ());
167+ BufferedImage fullScreen = robot .createScreenCapture (screen );
168+ ImageIO .write (fullScreen , "png" , new File ("fullScreen.png" ));
169+ } catch (Exception e ) {}
148170 throw new Error ("JSpinner buttons don't conform to most platform conventions" );
149171 }
150172 }
0 commit comments