Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/8021253/bug8021253.java
41153 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
24
import java.io.File;
25
import java.io.IOException;
26
import java.awt.BorderLayout;
27
import java.awt.Robot;
28
import java.awt.Toolkit;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.awt.event.KeyEvent;
32
import javax.swing.JFileChooser;
33
import javax.swing.JFrame;
34
import javax.swing.SwingUtilities;
35
36
/**
37
* @test
38
* @key headful
39
* @bug 8021253
40
* @author Alexander Scherbatiy
41
* @summary JFileChooser does not react on pressing enter since java 7
42
* @run main bug8021253
43
*/
44
45
public class bug8021253 {
46
47
private static volatile boolean defaultKeyPressed;
48
private static JFileChooser fileChooser;
49
private static File file;
50
private static JFrame frame;
51
52
public static void main(String[] args) throws Exception {
53
try {
54
Robot robot = new Robot();
55
robot.setAutoDelay(100);
56
57
SwingUtilities.invokeAndWait(new Runnable() {
58
public void run() {
59
createAndShowGUI();
60
}
61
});
62
63
robot.waitForIdle();
64
robot.delay(1000);
65
66
SwingUtilities.invokeAndWait(new Runnable() {
67
public void run() {
68
fileChooser.setSelectedFile(file);
69
}
70
});
71
72
robot.waitForIdle();
73
74
robot.keyPress(KeyEvent.VK_ENTER);
75
robot.keyRelease(KeyEvent.VK_ENTER);
76
robot.waitForIdle();
77
78
if (!defaultKeyPressed) {
79
throw new RuntimeException("Default button is not pressed");
80
}
81
} finally {
82
if (frame != null) {
83
SwingUtilities.invokeAndWait(frame::dispose);
84
}
85
}
86
}
87
88
private static void createAndShowGUI() {
89
90
file = getTempFile();
91
92
frame = new JFrame("Test");
93
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
94
frame.setSize(200, 300);
95
96
fileChooser = new JFileChooser(file.getParentFile());
97
fileChooser.addActionListener(new ActionListener() {
98
@Override
99
public void actionPerformed(ActionEvent e) {
100
defaultKeyPressed = true;
101
frame.dispose();
102
}
103
});
104
105
frame.getContentPane().add(BorderLayout.CENTER, fileChooser);
106
frame.setSize(fileChooser.getPreferredSize());
107
frame.setLocationRelativeTo(null);
108
frame.setVisible(true);
109
}
110
111
private static File getTempFile() {
112
try {
113
File temp = File.createTempFile("test", ".txt");
114
temp.deleteOnExit();
115
return temp;
116
} catch (IOException ex) {
117
throw new RuntimeException(ex);
118
}
119
}
120
}
121
122