Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFormattedTextField/7070795/JFormattedTextFieldTest.java
41153 views
1
/*
2
* Copyright (c) 2016, 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
/*
25
* @test
26
* @bug 7070795
27
* @summary High contrast colour scheme fails to be applied to JFormattedTextField
28
* @requires (os.family == "windows")
29
* @run main/manual JFormattedTextFieldTest
30
*/
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.text.NumberFormat;
36
import javax.swing.JButton;
37
import javax.swing.JFormattedTextField;
38
import javax.swing.JFrame;
39
import javax.swing.JLabel;
40
import javax.swing.JPanel;
41
import javax.swing.JTextField;
42
import javax.swing.SwingUtilities;
43
import javax.swing.UIManager;
44
45
public class JFormattedTextFieldTest implements ActionListener {
46
47
private static GridBagLayout layout;
48
private static JPanel mainControlPanel;
49
private static JPanel resultButtonPanel;
50
private static JLabel instructionText;
51
private static JButton passButton;
52
private static JButton failButton;
53
private static JFrame mainFrame;
54
55
public static void main(String[] args) throws Exception {
56
JFormattedTextFieldTest jFormattedTextFieldTest = new JFormattedTextFieldTest();
57
}
58
59
public JFormattedTextFieldTest() throws Exception {
60
createUI();
61
}
62
63
public final void createUI() throws Exception {
64
65
UIManager.setLookAndFeel("com.sun.java.swing.plaf."
66
+ "windows.WindowsLookAndFeel");
67
68
SwingUtilities.invokeAndWait(() -> {
69
70
mainFrame = new JFrame("Window LAF JFormattedTextField Test");
71
layout = new GridBagLayout();
72
mainControlPanel = new JPanel(layout);
73
resultButtonPanel = new JPanel(layout);
74
75
GridBagConstraints gbc = new GridBagConstraints();
76
String instructions
77
= "<html>INSTRUCTIONS:<br>"
78
+ "Set Windows Theme to HighContrast#1.<br><br>"
79
+ "(ControlPanel->Personalization->High Contrast#1)<br><br>"
80
+ "If TextFiled colors are same test"
81
+ " passes else failed.<br><br></html>";
82
83
instructionText = new JLabel();
84
instructionText.setText(instructions);
85
86
gbc.gridx = 0;
87
gbc.gridy = 0;
88
gbc.fill = GridBagConstraints.HORIZONTAL;
89
mainControlPanel.add(instructionText, gbc);
90
91
passButton = new JButton("Pass");
92
passButton.setActionCommand("Pass");
93
passButton.addActionListener(JFormattedTextFieldTest.this);
94
failButton = new JButton("Fail");
95
failButton.setActionCommand("Fail");
96
failButton.addActionListener(JFormattedTextFieldTest.this);
97
gbc.gridx = 0;
98
gbc.gridy = 0;
99
resultButtonPanel.add(passButton, gbc);
100
gbc.gridx = 1;
101
gbc.gridy = 0;
102
resultButtonPanel.add(failButton, gbc);
103
gbc.gridx = 3;
104
gbc.gridy = 0;
105
resultButtonPanel.add(new JTextField("12345"), gbc);
106
107
NumberFormat format = NumberFormat.getIntegerInstance();
108
format.setMaximumIntegerDigits(5);
109
JFormattedTextField formatted = new JFormattedTextField(format);
110
formatted.setText("67891");
111
gbc.gridx = 5;
112
gbc.gridy = 0;
113
resultButtonPanel.add(formatted, gbc);
114
gbc.gridx = 0;
115
gbc.gridy = 1;
116
mainControlPanel.add(resultButtonPanel, gbc);
117
118
mainFrame.add(mainControlPanel);
119
mainFrame.setSize(400, 200);
120
mainFrame.setLocationRelativeTo(null);
121
mainFrame.setVisible(true);
122
});
123
}
124
125
@Override
126
public void actionPerformed(ActionEvent evt) {
127
if (evt.getSource() instanceof JButton) {
128
JButton btn = (JButton) evt.getSource();
129
cleanUp();
130
switch (btn.getActionCommand()) {
131
case "Pass":
132
break;
133
case "Fail":
134
throw new AssertionError("User Clicked Fail!");
135
}
136
}
137
}
138
139
private static void cleanUp() {
140
mainFrame.dispose();
141
}
142
143
}
144
145
146