Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JToolBar/4529206/bug4529206.java
38918 views
/*1* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* @test26@bug 452920627@summary JToolBar - setFloating does not work correctly28@author Konstantin Eremin29@run main bug452920630*/3132import javax.swing.*;33import java.awt.*;34import java.awt.event.ActionEvent;35import java.awt.event.ActionListener;3637public class bug4529206 extends JFrame {38static JFrame frame;39static JToolBar jToolBar1;40public bug4529206() {41setDefaultCloseOperation(EXIT_ON_CLOSE);42JPanel jPanFrame = (JPanel) this.getContentPane();43jPanFrame.setLayout(new BorderLayout());44this.setSize(new Dimension(200, 100));45this.setLocation(125, 75);46this.setTitle("Test Floating Toolbar");47jToolBar1 = new JToolBar();48JButton jButton1 = new JButton("Float");49jPanFrame.add(jToolBar1, BorderLayout.NORTH);50JTextField tf = new JTextField("click here");51jPanFrame.add(tf);52jToolBar1.add(jButton1, null);53jButton1.addActionListener(new ActionListener() {54public void actionPerformed(ActionEvent e) {55buttonPressed(e);56}57});58makeToolbarFloat();59setVisible(true);60}6162private void makeToolbarFloat() {63javax.swing.plaf.basic.BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) jToolBar1.getUI();64if (!ui.isFloating()) {65ui.setFloatingLocation(100, 100);66ui.setFloating(true, jToolBar1.getLocation());67}68}6970private void buttonPressed(ActionEvent e) {71makeToolbarFloat();72}7374public static void main(String[] args) throws Exception {75SwingUtilities.invokeAndWait(new Runnable() {76public void run() {77frame = new bug4529206();78}79});80Robot robot = new Robot();81robot.waitForIdle();82SwingUtilities.invokeAndWait(new Runnable() {83public void run() {84if (frame.isFocused()) {85throw (new RuntimeException("setFloating does not work correctly"));86}87}88});89}90}919293