11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
24- /*
25- * @test
26- * @key headful
27- * @bug 4529206
28- * @summary JToolBar - setFloating does not work correctly
29- * @run main bug4529206
30- */
31-
3224import java .awt .BorderLayout ;
3325import java .awt .Dimension ;
3426import java .awt .Robot ;
35- import java .awt .event .ActionEvent ;
36- import java .awt .event .ActionListener ;
3727import javax .swing .JButton ;
3828import javax .swing .JFrame ;
3929import javax .swing .JPanel ;
4030import javax .swing .JTextField ;
4131import javax .swing .JToolBar ;
4232import javax .swing .SwingUtilities ;
4333
34+ /*
35+ * @test
36+ * @key headful
37+ * @bug 4529206
38+ * @summary JToolBar - setFloating does not work correctly
39+ * @run main bug4529206
40+ */
41+
4442public class bug4529206 {
4543 static JFrame frame ;
4644 static JToolBar jToolBar1 ;
@@ -58,11 +56,7 @@ private static void test() {
5856 JTextField tf = new JTextField ("click here" );
5957 jPanFrame .add (tf );
6058 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 ());
6660
6761 frame .setUndecorated (true );
6862 frame .setLocationRelativeTo (null );
@@ -77,32 +71,24 @@ private static void makeToolbarFloat() {
7771 }
7872 }
7973
80- private static void buttonPressed (ActionEvent e ) {
74+ private static void buttonPressed () {
8175 makeToolbarFloat ();
8276 }
8377
8478 public static void main (String [] args ) throws Exception {
8579 try {
86- SwingUtilities .invokeAndWait (new Runnable () {
87- public void run () {
88- test ();
89- }
90- });
80+ SwingUtilities .invokeAndWait (() -> test ());
9181 Robot robot = new Robot ();
92- robot .waitForIdle ( );
82+ robot .setAutoWaitForIdle ( true );
9383 robot .delay (1000 );
9484
95- SwingUtilities .invokeAndWait (() -> {
96- makeToolbarFloat ();
97- });
85+ SwingUtilities .invokeAndWait (() -> makeToolbarFloat ());
86+ robot .delay (300 );
9887
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" );
10692 }
10793 });
10894 } finally {
0 commit comments