mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-05 11:15:13 +00:00
8367784: java/awt/Focus/InitialFocusTest/InitialFocusTest1.java failed with Wrong focus owner
Reviewed-by: honkar, dnguyen
This commit is contained in:
parent
c0815e40b6
commit
5855fd2f65
@ -22,8 +22,10 @@
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
@ -39,27 +41,36 @@ public class InitialFocusTest1 extends Frame implements FocusListener {
|
||||
Button button1 = new Button("Button1");
|
||||
Button button2 = new Button("Button2");
|
||||
private static volatile Object focused;
|
||||
private static InitialFocusTest1 app;
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
InitialFocusTest1 app = new InitialFocusTest1();
|
||||
try {
|
||||
app.setSize(200, 200);
|
||||
app.setLocationRelativeTo(null);
|
||||
app.setLayout(new FlowLayout());
|
||||
Robot robot = new Robot();
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
app = new InitialFocusTest1();
|
||||
app.setLayout(new FlowLayout());
|
||||
|
||||
app.button1.addFocusListener(app);
|
||||
app.button2.addFocusListener(app);
|
||||
app.add(app.button1);
|
||||
app.add(app.button2);
|
||||
app.setVisible(true);
|
||||
app.button2.requestFocus();
|
||||
app.button1.addFocusListener(app);
|
||||
app.button2.addFocusListener(app);
|
||||
app.add(app.button1);
|
||||
app.add(app.button2);
|
||||
|
||||
app.setSize(200, 200);
|
||||
app.setLocationRelativeTo(null);
|
||||
app.setVisible(true);
|
||||
});
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
app.button2.requestFocus();
|
||||
});
|
||||
// wait for the very very last focus event
|
||||
Thread.sleep(10000);
|
||||
robot.delay(1000);
|
||||
if (app.button2 != focused) {
|
||||
throw new RuntimeException("Wrong focus owner: " + focused);
|
||||
}
|
||||
} finally {
|
||||
app.dispose();
|
||||
EventQueue.invokeAndWait(() -> app.dispose());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user