Skip to content

Commit

Permalink
8288707: javax/swing/JToolBar/4529206/bug4529206.java: setFloating do…
Browse files Browse the repository at this point in the history
…es not work correctly

Reviewed-by: tr, serb
  • Loading branch information
prsadhuk committed Jun 30, 2022
1 parent c3addbb commit feb223a
Showing 1 changed file with 54 additions and 29 deletions.
83 changes: 54 additions & 29 deletions test/jdk/javax/swing/JToolBar/4529206/bug4529206.java
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -58,36 +65,54 @@ public void actionPerformed(ActionEvent e) {
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);
ui.setFloating(true, jToolBar1.getLocation());
}
}

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();
}
});
}
}
}

1 comment on commit feb223a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.