Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/Box/TestBoxFiller.java
41152 views
1
/*
2
* Copyright (c) 2020, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
@bug 8253016
26
@key headful
27
@summary Verifies Box.Filler components should be unfocusable by default
28
@run main TestBoxFiller
29
*/
30
import java.awt.ContainerOrderFocusTraversalPolicy;
31
import java.awt.KeyboardFocusManager;
32
import java.beans.PropertyChangeEvent;
33
import javax.swing.Box;
34
import javax.swing.JFrame;
35
import javax.swing.JTextField;
36
import javax.swing.SwingUtilities;
37
import java.awt.Robot;
38
import java.awt.event.KeyEvent;
39
40
public class TestBoxFiller
41
{
42
private static JFrame frame;
43
private static void showFocusOwner(PropertyChangeEvent e)
44
{
45
Object c = e.getNewValue();
46
if (c instanceof Box.Filler) {
47
throw new RuntimeException("Box.Filler having focus");
48
}
49
}
50
51
public static void main(String[] args) throws Exception
52
{
53
try {
54
Robot robot = new Robot();
55
robot.setAutoDelay(100);
56
SwingUtilities.invokeAndWait(() -> {
57
frame = new JFrame();
58
KeyboardFocusManager m = KeyboardFocusManager.getCurrentKeyboardFocusManager();
59
m.addPropertyChangeListener("focusOwner", TestBoxFiller::showFocusOwner);
60
61
Box box = Box.createHorizontalBox();
62
JTextField tf1 = new JTextField("Test");
63
tf1.setColumns(40);
64
JTextField tf2 = new JTextField("Test");
65
tf2.setColumns(40);
66
box.add(tf1);
67
box.add(Box.createHorizontalStrut(20));
68
box.add(tf2);
69
frame.setContentPane(box);
70
frame.setFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy());
71
frame.pack();
72
frame.setVisible(true);
73
frame.setLocationRelativeTo(null);
74
tf1.requestFocusInWindow();
75
});
76
robot.waitForIdle();
77
robot.keyPress(KeyEvent.VK_TAB);
78
robot.keyRelease(KeyEvent.VK_TAB);
79
} finally {
80
if (frame != null) {
81
SwingUtilities.invokeAndWait(frame::dispose);
82
}
83
}
84
}
85
}
86
87