Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JToolBar/4529206/bug4529206.java
41153 views
1
/*
2
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
* @test
28
* @key headful
29
* @bug 4529206
30
* @summary JToolBar - setFloating does not work correctly
31
* @author Konstantin Eremin
32
* @run main bug4529206
33
*/
34
35
import javax.swing.*;
36
import java.awt.*;
37
import java.awt.event.ActionEvent;
38
import java.awt.event.ActionListener;
39
40
public class bug4529206 extends JFrame {
41
static JFrame frame;
42
static JToolBar jToolBar1;
43
public bug4529206() {
44
setDefaultCloseOperation(EXIT_ON_CLOSE);
45
JPanel jPanFrame = (JPanel) this.getContentPane();
46
jPanFrame.setLayout(new BorderLayout());
47
this.setSize(new Dimension(200, 100));
48
this.setLocation(125, 75);
49
this.setTitle("Test Floating Toolbar");
50
jToolBar1 = new JToolBar();
51
JButton jButton1 = new JButton("Float");
52
jPanFrame.add(jToolBar1, BorderLayout.NORTH);
53
JTextField tf = new JTextField("click here");
54
jPanFrame.add(tf);
55
jToolBar1.add(jButton1, null);
56
jButton1.addActionListener(new ActionListener() {
57
public void actionPerformed(ActionEvent e) {
58
buttonPressed(e);
59
}
60
});
61
makeToolbarFloat();
62
setVisible(true);
63
}
64
65
private void makeToolbarFloat() {
66
javax.swing.plaf.basic.BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) jToolBar1.getUI();
67
if (!ui.isFloating()) {
68
ui.setFloatingLocation(100, 100);
69
ui.setFloating(true, jToolBar1.getLocation());
70
}
71
}
72
73
private void buttonPressed(ActionEvent e) {
74
makeToolbarFloat();
75
}
76
77
public static void main(String[] args) throws Exception {
78
SwingUtilities.invokeAndWait(new Runnable() {
79
public void run() {
80
frame = new bug4529206();
81
}
82
});
83
Robot robot = new Robot();
84
robot.waitForIdle();
85
SwingUtilities.invokeAndWait(new Runnable() {
86
public void run() {
87
if (frame.isFocused()) {
88
throw (new RuntimeException("setFloating does not work correctly"));
89
}
90
}
91
});
92
}
93
}
94
95