Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSpinner/WrongEditorTextFieldFont/FontSetByLaF.java
41153 views
1
/*
2
* Copyright (c) 2018, 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.awt.EventQueue;
25
import java.awt.Font;
26
27
import javax.swing.JFormattedTextField;
28
import javax.swing.JSpinner;
29
import javax.swing.JSpinner.DefaultEditor;
30
import javax.swing.SwingUtilities;
31
import javax.swing.UIManager;
32
import javax.swing.UnsupportedLookAndFeelException;
33
34
import static javax.swing.UIManager.getInstalledLookAndFeels;
35
36
/**
37
* @test
38
* @key headful
39
* @bug 8205144
40
* @summary Verify font of the text field is changed to the font of
41
* JSpinner if the font of text field was NOT set by the user and look
42
* and feel tried to set it to default font of the TextUI
43
*/
44
public final class FontSetByLaF {
45
46
public static void main(final String[] args) throws Exception {
47
for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
48
EventQueue.invokeAndWait(() -> setLookAndFeel(laf));
49
EventQueue.invokeAndWait(() -> {
50
51
JSpinner spinner = new JSpinner();
52
DefaultEditor editor = (DefaultEditor) spinner.getEditor();
53
JFormattedTextField textField = editor.getTextField();
54
55
Font before = textField.getFont();
56
SwingUtilities.updateComponentTreeUI(spinner);
57
Font after = textField.getFont();
58
59
if (!before.equals(after)) {
60
System.err.println("Before: " + before);
61
System.err.println("After: " + after);
62
throw new RuntimeException();
63
}
64
});
65
}
66
}
67
68
private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
69
try {
70
UIManager.setLookAndFeel(laf.getClassName());
71
System.err.println("LookAndFeel: " + laf.getClassName());
72
} catch (final UnsupportedLookAndFeelException ignored) {
73
System.err.println(
74
"Unsupported LookAndFeel: " + laf.getClassName());
75
} catch (ClassNotFoundException | InstantiationException |
76
IllegalAccessException e) {
77
throw new RuntimeException(e);
78
}
79
}
80
}
81
82