1
1
/*
2
- * Copyright (c) 2004, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2004, 2023 , 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
21
21
* questions.
22
22
*/
23
23
24
- /*
25
- * @test
26
- * @key headful
27
- * @bug 4529206
28
- * @summary JToolBar - setFloating does not work correctly
29
- * @run main bug4529206
30
- */
31
-
32
24
import java .awt .BorderLayout ;
33
25
import java .awt .Dimension ;
34
26
import java .awt .Robot ;
35
- import java .awt .event .ActionEvent ;
36
- import java .awt .event .ActionListener ;
37
27
import javax .swing .JButton ;
38
28
import javax .swing .JFrame ;
39
29
import javax .swing .JPanel ;
40
30
import javax .swing .JTextField ;
41
31
import javax .swing .JToolBar ;
42
32
import javax .swing .SwingUtilities ;
43
33
34
+ /*
35
+ * @test
36
+ * @key headful
37
+ * @bug 4529206
38
+ * @summary JToolBar - setFloating does not work correctly
39
+ * @run main bug4529206
40
+ */
41
+
44
42
public class bug4529206 {
45
43
static JFrame frame ;
46
44
static JToolBar jToolBar1 ;
@@ -58,11 +56,7 @@ private static void test() {
58
56
JTextField tf = new JTextField ("click here" );
59
57
jPanFrame .add (tf );
60
58
jToolBar1 .add (jButton1 , null );
61
- jButton1 .addActionListener (new ActionListener () {
62
- public void actionPerformed (ActionEvent e ) {
63
- buttonPressed (e );
64
- }
65
- });
59
+ jButton1 .addActionListener (e -> buttonPressed ());
66
60
67
61
frame .setUndecorated (true );
68
62
frame .setLocationRelativeTo (null );
@@ -77,32 +71,24 @@ private static void makeToolbarFloat() {
77
71
}
78
72
}
79
73
80
- private static void buttonPressed (ActionEvent e ) {
74
+ private static void buttonPressed () {
81
75
makeToolbarFloat ();
82
76
}
83
77
84
78
public static void main (String [] args ) throws Exception {
85
79
try {
86
- SwingUtilities .invokeAndWait (new Runnable () {
87
- public void run () {
88
- test ();
89
- }
90
- });
80
+ SwingUtilities .invokeAndWait (() -> test ());
91
81
Robot robot = new Robot ();
92
- robot .waitForIdle ( );
82
+ robot .setAutoWaitForIdle ( true );
93
83
robot .delay (1000 );
94
84
95
- SwingUtilities .invokeAndWait (() -> {
96
- makeToolbarFloat ();
97
- });
85
+ SwingUtilities .invokeAndWait (() -> makeToolbarFloat ());
86
+ robot .delay (300 );
98
87
99
- robot .waitForIdle ();
100
- SwingUtilities .invokeAndWait (new Runnable () {
101
- public void run () {
102
- if (frame .isFocused ()) {
103
- throw
104
- new RuntimeException ("setFloating does not work correctly" );
105
- }
88
+ SwingUtilities .invokeAndWait (() -> {
89
+ if (frame .isFocused ()) {
90
+ throw
91
+ new RuntimeException ("setFloating does not work correctly" );
106
92
}
107
93
});
108
94
} finally {
0 commit comments