1
1
/*
2
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2016, 2019, 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
24
24
/*
25
25
* @test
26
26
* @key headful
27
- * @bug 8145896
27
+ * @bug 8145896 8194944
28
28
* @summary JInternalFrame setMaximum before adding to desktop throws null pointer exception
29
29
* @library ../../regtesthelpers
30
30
* @build Util
31
31
* @run main TestJInternalFrameMaximize
32
32
*/
33
+
33
34
import java .awt .Point ;
34
35
import java .awt .Robot ;
35
36
import java .awt .event .ActionEvent ;
@@ -55,18 +56,27 @@ public class TestJInternalFrameMaximize {
55
56
private static JMenuItem menuItem ;
56
57
private static Robot robot ;
57
58
private static volatile String errorMessage = "" ;
59
+ private static volatile boolean isFrameShowing ;
58
60
59
61
public static void main (String [] args ) throws Exception {
60
62
robot = new Robot ();
63
+ robot .setAutoDelay (100 );
61
64
UIManager .LookAndFeelInfo [] lookAndFeelArray
62
65
= UIManager .getInstalledLookAndFeels ();
63
66
for (UIManager .LookAndFeelInfo lookAndFeelItem : lookAndFeelArray ) {
64
- String lookAndFeelString = lookAndFeelItem .getClassName ();
65
- if (tryLookAndFeel (lookAndFeelString )) {
66
- createUI ();
67
+ try {
68
+ String lookAndFeelString = lookAndFeelItem .getClassName ();
69
+ if (tryLookAndFeel (lookAndFeelString )) {
70
+ createUI ();
71
+ robot .waitForIdle ();
72
+ blockTillDisplayed (frame );
73
+ executeTest ();
74
+ robot .delay (1000 );
75
+ }
76
+ } finally {
77
+ frame .dispose ();
78
+ isFrameShowing = false ;
67
79
robot .waitForIdle ();
68
- executeTest ();
69
- robot .delay (1000 );
70
80
}
71
81
}
72
82
if (!"" .equals (errorMessage )) {
@@ -113,8 +123,6 @@ private static void createUI() throws Exception {
113
123
} catch (PropertyVetoException ex ) {
114
124
} catch (RuntimeException ex ) {
115
125
errorMessage = "Test Failed" ;
116
- } finally {
117
- frame .dispose ();
118
126
}
119
127
});
120
128
menu .add (menuItem );
@@ -124,8 +132,21 @@ private static void createUI() throws Exception {
124
132
});
125
133
}
126
134
127
- private static void executeTest () throws Exception {
135
+ private static void blockTillDisplayed (JFrame frame ) throws Exception {
136
+ while (!isFrameShowing ) {
137
+ try {
138
+ SwingUtilities .invokeAndWait (()-> isFrameShowing = frame .isShowing ());
139
+ if (!isFrameShowing ) {
140
+ Thread .sleep (1000 );
141
+ }
142
+ } catch (InterruptedException ex ) {
143
+ } catch (Exception ex ) {
144
+ throw new RuntimeException (ex );
145
+ }
146
+ }
147
+ }
128
148
149
+ private static void executeTest () throws Exception {
129
150
Point point = Util .getCenterPoint (menu );
130
151
performMouseOperations (point );
131
152
point = Util .getCenterPoint (menuItem );
0 commit comments