Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JSpinner/4973721/bug4973721.java
38853 views
1
/*
2
* Copyright (c) 2013, 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
/* @test
24
@bug 4973721
25
@summary Up and Down Arrow key buttons are not working for the JSpinner in Synth LAF
26
@library ../../regtesthelpers
27
@build Util
28
@author Oleg Mokhovikov
29
@run main bug4973721
30
*/
31
32
import java.awt.Robot;
33
import javax.swing.event.ChangeListener;
34
import javax.swing.event.ChangeEvent;
35
import java.awt.event.KeyEvent;
36
import java.awt.event.FocusListener;
37
import java.awt.event.FocusEvent;
38
import javax.swing.*;
39
40
public class bug4973721 implements ChangeListener, FocusListener {
41
static volatile boolean bStateChanged = false;
42
static volatile boolean bFocusGained = false;
43
static JSpinner spinner;
44
static final Object listener = new bug4973721();
45
46
public void focusLost(FocusEvent e) {}
47
48
public synchronized void focusGained(FocusEvent e) {
49
System.out.println("focusGained");
50
bFocusGained = true;
51
notifyAll();
52
}
53
54
public synchronized void stateChanged(ChangeEvent e) {
55
System.out.println("stateChanged");
56
bStateChanged = true;
57
notifyAll();
58
}
59
60
public static void main(String[] args) throws Exception {
61
UIManager.setLookAndFeel("javax.swing.plaf.synth.SynthLookAndFeel");
62
63
SwingUtilities.invokeAndWait(new Runnable() {
64
public void run() {
65
final JFrame frame = new JFrame();
66
spinner = new JSpinner();
67
frame.getContentPane().add(spinner);
68
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
69
70
frame.pack();
71
frame.setVisible(true);
72
spinner.addChangeListener((ChangeListener)listener);
73
spinner.addFocusListener((FocusListener)listener);
74
spinner.requestFocus();
75
76
}
77
});
78
79
synchronized(listener) {
80
if (!bFocusGained) {
81
System.out.println("waiting focusGained...");
82
try { listener.wait(5000); } catch (InterruptedException e) {}
83
}
84
}
85
86
boolean hasFocus = Util.invokeOnEDT(new java.util.concurrent.Callable<Boolean>() {
87
@Override
88
public Boolean call() throws Exception {
89
return spinner.hasFocus();
90
}
91
});
92
93
if (!bFocusGained && !hasFocus) {
94
throw new RuntimeException("Couldn't request focus for spinner");
95
}
96
Robot robot = new Robot();
97
robot.setAutoDelay(50);
98
99
Util.hitKeys(robot, KeyEvent.VK_UP);
100
robot.waitForIdle();
101
Thread.sleep(1000);
102
103
if (!bStateChanged) {
104
throw new RuntimeException("Up arrow key button doesn't work for a spinner in Synth L&F");
105
}
106
107
bStateChanged = false;
108
109
Util.hitKeys(robot, KeyEvent.VK_DOWN);
110
robot.waitForIdle();
111
Thread.sleep(1000);
112
113
if (!bStateChanged) {
114
throw new RuntimeException("Down arrow key button doesn't work for a spinner in Synth L&F");
115
}
116
}
117
}
118
119