From 808bb1f7bc5025b4ab01e4e9057feebd253b95a7 Mon Sep 17 00:00:00 2001 From: Harshitha Onkar Date: Thu, 17 Aug 2023 20:37:06 +0000 Subject: [PATCH] 8314246: javax/swing/JToolBar/4529206/bug4529206.java fails intermittently on Linux Reviewed-by: dnguyen, serb --- .../swing/JToolBar/4529206/bug4529206.java | 52 +++++++------------ 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/test/jdk/javax/swing/JToolBar/4529206/bug4529206.java b/test/jdk/javax/swing/JToolBar/4529206/bug4529206.java index 8844254dba4..ed4f062b24c 100644 --- a/test/jdk/javax/swing/JToolBar/4529206/bug4529206.java +++ b/test/jdk/javax/swing/JToolBar/4529206/bug4529206.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,19 +21,9 @@ * questions. */ -/* - * @test - * @key headful - * @bug 4529206 - * @summary JToolBar - setFloating does not work correctly - * @run main bug4529206 - */ - import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Robot; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; @@ -41,6 +31,14 @@ import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.SwingUtilities; +/* + * @test + * @key headful + * @bug 4529206 + * @summary JToolBar - setFloating does not work correctly + * @run main bug4529206 + */ + public class bug4529206 { static JFrame frame; static JToolBar jToolBar1; @@ -58,11 +56,7 @@ public class bug4529206 { JTextField tf = new JTextField("click here"); jPanFrame.add(tf); jToolBar1.add(jButton1, null); - jButton1.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - buttonPressed(e); - } - }); + jButton1.addActionListener(e -> buttonPressed()); frame.setUndecorated(true); frame.setLocationRelativeTo(null); @@ -77,32 +71,24 @@ public class bug4529206 { } } - private static void buttonPressed(ActionEvent e) { + private static void buttonPressed() { makeToolbarFloat(); } public static void main(String[] args) throws Exception { try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - test(); - } - }); + SwingUtilities.invokeAndWait(() -> test()); Robot robot = new Robot(); - robot.waitForIdle(); + robot.setAutoWaitForIdle(true); robot.delay(1000); - SwingUtilities.invokeAndWait(() -> { - makeToolbarFloat(); - }); + SwingUtilities.invokeAndWait(() -> makeToolbarFloat()); + robot.delay(300); - robot.waitForIdle(); - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - if (frame.isFocused()) { - throw - new RuntimeException("setFloating does not work correctly"); - } + SwingUtilities.invokeAndWait(() -> { + if (frame.isFocused()) { + throw + new RuntimeException("setFloating does not work correctly"); } }); } finally {