< prev index next >

test/javax/swing/JSpinner/5012888/bug5012888.java

Print this page

        

@@ -22,46 +22,89 @@
  */
 
 /*
  * @test 1.0 04/04/23
  * @key headful
- * @bug 5012888
+ * @bug 5012888 8169958
  * @summary REGRESSION: Click & hold on arrow of JSpinner only transfers focus
  * @author Konstantin Eremin
  * @run main bug5012888
  */
 
-import javax.swing.*;
-import javax.swing.event.*;
-import java.awt.*;
-import java.awt.event.*;
-
-public class bug5012888 extends JFrame {
-    JSpinner spinner1, spinner2;
-    public bug5012888() {
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.event.InputEvent;
+
+import javax.swing.JFrame;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.SwingUtilities;
+
+public class bug5012888 {
+    static JSpinner spinner1, spinner2;
+    static JFrame frame;
+
+    public static Container createPanel(JFrame frame) {
       spinner1 = new JSpinner(new SpinnerNumberModel(0, -1000, 1000, 1));
       spinner2 = new JSpinner(new SpinnerNumberModel(1, -1000, 1000, 1));
-      Container pane = getContentPane();
+        Container pane = frame.getContentPane();
       pane.setLayout(new BorderLayout());
       pane.add(spinner1, BorderLayout.NORTH);
       pane.add(spinner2, BorderLayout.SOUTH);
+        return pane;
     }
-    public void doTest() throws Exception {
+
+    public static void main(String[] argv) throws Exception {
         Robot robot = new Robot();
+        robot.setAutoDelay(800);
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                frame = new JFrame("Test");
+                frame.setContentPane(createPanel(frame));
+                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+                frame.setBounds(0, 0, 100, 100);
+                frame.pack();
+                frame.setVisible(true);
+            }
+        });
+
+        componentVisibleCheck(spinner2);
         robot.waitForIdle();
+        robot.delay(200);
         Point p = spinner2.getLocationOnScreen();
         Rectangle rect = spinner2.getBounds();
-        robot.mouseMove(p.x+rect.width-5, p.y+5);
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                robot.mouseMove(p.x + rect.width - 5, p.y + 5);
+            }
+        });
+        robot.waitForIdle();
         robot.mousePress(InputEvent.BUTTON1_MASK);
-        Thread.sleep(1000);
         robot.mouseRelease(InputEvent.BUTTON1_MASK);
-        if ( ((Integer) spinner2.getValue()).intValue() == 1 ) {
-            throw new Error("Spinner value should be more than 1");
+        robot.waitForIdle();
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                if (((Integer) spinner2.getValue()).intValue() == 1) {
+                    throw new RuntimeException("Spinner value should be more than 1");
+                } 
+            }
+        });
+    }
+
+    private static void componentVisibleCheck(Component component) throws Exception {
+        while (!component.isVisible()) {
+            try {
+                Thread.sleep(800);
+            } catch (Exception e) {
+                throw new Exception("test failed");
         }
     }
-    public static void main(String[] argv) throws Exception {
-        bug5012888 b = new bug5012888();
-        b.setBounds(0, 0, 100, 100);
-        b.setVisible(true);
-        b.doTest();
     }
 }
< prev index next >