Path: blob/master/test/jdk/javax/swing/JToolBar/4529206/bug4529206.java
41153 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/*26* @test27* @key headful28* @bug 452920629* @summary JToolBar - setFloating does not work correctly30* @author Konstantin Eremin31* @run main bug452920632*/3334import javax.swing.*;35import java.awt.*;36import java.awt.event.ActionEvent;37import java.awt.event.ActionListener;3839public class bug4529206 extends JFrame {40static JFrame frame;41static JToolBar jToolBar1;42public bug4529206() {43setDefaultCloseOperation(EXIT_ON_CLOSE);44JPanel jPanFrame = (JPanel) this.getContentPane();45jPanFrame.setLayout(new BorderLayout());46this.setSize(new Dimension(200, 100));47this.setLocation(125, 75);48this.setTitle("Test Floating Toolbar");49jToolBar1 = new JToolBar();50JButton jButton1 = new JButton("Float");51jPanFrame.add(jToolBar1, BorderLayout.NORTH);52JTextField tf = new JTextField("click here");53jPanFrame.add(tf);54jToolBar1.add(jButton1, null);55jButton1.addActionListener(new ActionListener() {56public void actionPerformed(ActionEvent e) {57buttonPressed(e);58}59});60makeToolbarFloat();61setVisible(true);62}6364private void makeToolbarFloat() {65javax.swing.plaf.basic.BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) jToolBar1.getUI();66if (!ui.isFloating()) {67ui.setFloatingLocation(100, 100);68ui.setFloating(true, jToolBar1.getLocation());69}70}7172private void buttonPressed(ActionEvent e) {73makeToolbarFloat();74}7576public static void main(String[] args) throws Exception {77SwingUtilities.invokeAndWait(new Runnable() {78public void run() {79frame = new bug4529206();80}81});82Robot robot = new Robot();83robot.waitForIdle();84SwingUtilities.invokeAndWait(new Runnable() {85public void run() {86if (frame.isFocused()) {87throw (new RuntimeException("setFloating does not work correctly"));88}89}90});91}92}939495