8288707: javax/swing/JToolBar/4529206/bug4529206.java: setFloating does not work correctly

Reviewed-by: tr, serb
This commit is contained in:
Prasanta Sadhukhan 2022-06-30 11:16:07 +00:00
parent c3addbb1c0
commit feb223aacf

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2022, 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
@ -28,27 +28,34 @@
* @key headful
* @bug 4529206
* @summary JToolBar - setFloating does not work correctly
* @author Konstantin Eremin
* @run main bug4529206
*/
import javax.swing.*;
import java.awt.*;
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;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
public class bug4529206 extends JFrame {
public class bug4529206 {
static JFrame frame;
static JToolBar jToolBar1;
public bug4529206() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jPanFrame = (JPanel) this.getContentPane();
static JButton jButton1;
private static void test() {
frame = new JFrame();
JPanel jPanFrame = (JPanel) frame.getContentPane();
jPanFrame.setLayout(new BorderLayout());
this.setSize(new Dimension(200, 100));
this.setLocation(125, 75);
this.setTitle("Test Floating Toolbar");
frame.setSize(new Dimension(200, 100));
frame.setTitle("Test Floating Toolbar");
jToolBar1 = new JToolBar();
JButton jButton1 = new JButton("Float");
jButton1 = new JButton("Float");
jPanFrame.add(jToolBar1, BorderLayout.NORTH);
JTextField tf = new JTextField("click here");
jPanFrame.add(tf);
@ -58,11 +65,13 @@ public class bug4529206 extends JFrame {
buttonPressed(e);
}
});
makeToolbarFloat();
setVisible(true);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void makeToolbarFloat() {
private static void makeToolbarFloat() {
javax.swing.plaf.basic.BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) jToolBar1.getUI();
if (!ui.isFloating()) {
ui.setFloatingLocation(100, 100);
@ -70,24 +79,40 @@ public class bug4529206 extends JFrame {
}
}
private void buttonPressed(ActionEvent e) {
private static void buttonPressed(ActionEvent e) {
makeToolbarFloat();
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
frame = new bug4529206();
}
});
Robot robot = new Robot();
robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (frame.isFocused()) {
throw (new RuntimeException("setFloating does not work correctly"));
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
test();
}
}
});
});
Robot robot = new Robot();
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
makeToolbarFloat();
});
robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (frame.isFocused()) {
throw
new RuntimeException("setFloating does not work correctly");
}
}
});
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}