Skip to content

Commit 5855fd2

Browse files
committed
8367784: java/awt/Focus/InitialFocusTest/InitialFocusTest1.java failed with Wrong focus owner
Reviewed-by: honkar, dnguyen
1 parent c0815e4 commit 5855fd2

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

test/jdk/java/awt/Focus/InitialFocusTest/InitialFocusTest1.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
*/
2323

2424
import java.awt.Button;
25+
import java.awt.EventQueue;
2526
import java.awt.FlowLayout;
2627
import java.awt.Frame;
28+
import java.awt.Robot;
2729
import java.awt.event.FocusEvent;
2830
import java.awt.event.FocusListener;
2931

@@ -39,27 +41,36 @@ public class InitialFocusTest1 extends Frame implements FocusListener {
3941
Button button1 = new Button("Button1");
4042
Button button2 = new Button("Button2");
4143
private static volatile Object focused;
44+
private static InitialFocusTest1 app;
4245

4346
public static void main(final String[] args) throws Exception {
44-
InitialFocusTest1 app = new InitialFocusTest1();
4547
try {
46-
app.setSize(200, 200);
47-
app.setLocationRelativeTo(null);
48-
app.setLayout(new FlowLayout());
48+
Robot robot = new Robot();
49+
EventQueue.invokeAndWait(() -> {
50+
app = new InitialFocusTest1();
51+
app.setLayout(new FlowLayout());
4952

50-
app.button1.addFocusListener(app);
51-
app.button2.addFocusListener(app);
52-
app.add(app.button1);
53-
app.add(app.button2);
54-
app.setVisible(true);
55-
app.button2.requestFocus();
53+
app.button1.addFocusListener(app);
54+
app.button2.addFocusListener(app);
55+
app.add(app.button1);
56+
app.add(app.button2);
57+
58+
app.setSize(200, 200);
59+
app.setLocationRelativeTo(null);
60+
app.setVisible(true);
61+
});
62+
robot.waitForIdle();
63+
robot.delay(1000);
64+
EventQueue.invokeAndWait(() -> {
65+
app.button2.requestFocus();
66+
});
5667
// wait for the very very last focus event
57-
Thread.sleep(10000);
68+
robot.delay(1000);
5869
if (app.button2 != focused) {
5970
throw new RuntimeException("Wrong focus owner: " + focused);
6071
}
6172
} finally {
62-
app.dispose();
73+
EventQueue.invokeAndWait(() -> app.dispose());
6374
}
6475
}
6576

0 commit comments

Comments
 (0)