|
24 | 24 | /*
|
25 | 25 | * @test
|
26 | 26 | * @key headful
|
27 |
| - * @bug 6827032 |
| 27 | + * @bug 6827032 8197825 |
28 | 28 | * @summary Color chooser with drag enabled shouldn't throw NPE
|
29 | 29 | * @author Peter Zhelezniakov
|
30 | 30 | * @library ../regtesthelpers
|
|
38 | 38 |
|
39 | 39 |
|
40 | 40 | public class Test6827032 {
|
41 |
| - |
42 | 41 | private static volatile Point point;
|
| 42 | + private static JFrame frame; |
43 | 43 | private static JColorChooser cc;
|
44 | 44 |
|
45 | 45 | public static void main(String[] args) throws Exception {
|
46 |
| - UIManager.setLookAndFeel(new NimbusLookAndFeel()); |
47 |
| - |
48 |
| - Robot robot = new Robot(); |
49 |
| - robot.setAutoDelay(50); |
50 |
| - |
51 |
| - |
52 |
| - SwingUtilities.invokeAndWait(new Runnable() { |
53 |
| - public void run() { |
54 |
| - createAndShowGUI(); |
| 46 | + try { |
| 47 | + UIManager.setLookAndFeel(new NimbusLookAndFeel()); |
| 48 | + |
| 49 | + Robot robot = new Robot(); |
| 50 | + robot.setAutoDelay(100); |
| 51 | + |
| 52 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 53 | + public void run() { |
| 54 | + createAndShowGUI(); |
| 55 | + } |
| 56 | + }); |
| 57 | + |
| 58 | + robot.waitForIdle(); |
| 59 | + robot.delay(1000); |
| 60 | + |
| 61 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 62 | + public void run() { |
| 63 | + Component previewPanel = Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel"); |
| 64 | + point = previewPanel.getLocationOnScreen(); |
| 65 | + } |
| 66 | + }); |
| 67 | + |
| 68 | + point.translate(5, 5); |
| 69 | + |
| 70 | + robot.mouseMove(point.x, point.y); |
| 71 | + robot.waitForIdle(); |
| 72 | + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
| 73 | + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
| 74 | + robot.waitForIdle(); |
| 75 | + robot.delay(1000); |
| 76 | + } finally { |
| 77 | + if (frame != null) { |
| 78 | + SwingUtilities.invokeAndWait(() -> frame.dispose()); |
55 | 79 | }
|
56 |
| - }); |
57 |
| - |
58 |
| - robot.waitForIdle(); |
59 |
| - |
60 |
| - SwingUtilities.invokeAndWait(new Runnable() { |
61 |
| - public void run() { |
62 |
| - Component previewPanel = Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel"); |
63 |
| - point = previewPanel.getLocationOnScreen(); |
64 |
| - } |
65 |
| - }); |
66 |
| - |
67 |
| - point.translate(5, 5); |
68 |
| - |
69 |
| - robot.mouseMove(point.x, point.y); |
70 |
| - robot.mousePress(InputEvent.BUTTON1_MASK); |
71 |
| - robot.mouseRelease(InputEvent.BUTTON1_MASK); |
| 80 | + } |
72 | 81 | }
|
73 | 82 |
|
74 | 83 |
|
75 | 84 | private static void createAndShowGUI() {
|
76 |
| - JFrame frame = new JFrame(Test6827032.class.getName()); |
| 85 | + frame = new JFrame(Test6827032.class.getName()); |
77 | 86 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
78 | 87 | cc = new JColorChooser();
|
79 | 88 | cc.setDragEnabled(true);
|
80 | 89 | frame.add(cc);
|
81 | 90 | frame.pack();
|
| 91 | + frame.setLocationRelativeTo(null); |
82 | 92 | frame.setVisible(true);
|
83 | 93 | }
|
84 | 94 | }
|
0 commit comments