Path: blob/master/test/jdk/javax/swing/JSpinner/WrongEditorTextFieldFont/FontSetByLaF.java
41153 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.EventQueue;24import java.awt.Font;2526import javax.swing.JFormattedTextField;27import javax.swing.JSpinner;28import javax.swing.JSpinner.DefaultEditor;29import javax.swing.SwingUtilities;30import javax.swing.UIManager;31import javax.swing.UnsupportedLookAndFeelException;3233import static javax.swing.UIManager.getInstalledLookAndFeels;3435/**36* @test37* @key headful38* @bug 820514439* @summary Verify font of the text field is changed to the font of40* JSpinner if the font of text field was NOT set by the user and look41* and feel tried to set it to default font of the TextUI42*/43public final class FontSetByLaF {4445public static void main(final String[] args) throws Exception {46for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {47EventQueue.invokeAndWait(() -> setLookAndFeel(laf));48EventQueue.invokeAndWait(() -> {4950JSpinner spinner = new JSpinner();51DefaultEditor editor = (DefaultEditor) spinner.getEditor();52JFormattedTextField textField = editor.getTextField();5354Font before = textField.getFont();55SwingUtilities.updateComponentTreeUI(spinner);56Font after = textField.getFont();5758if (!before.equals(after)) {59System.err.println("Before: " + before);60System.err.println("After: " + after);61throw new RuntimeException();62}63});64}65}6667private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {68try {69UIManager.setLookAndFeel(laf.getClassName());70System.err.println("LookAndFeel: " + laf.getClassName());71} catch (final UnsupportedLookAndFeelException ignored) {72System.err.println(73"Unsupported LookAndFeel: " + laf.getClassName());74} catch (ClassNotFoundException | InstantiationException |75IllegalAccessException e) {76throw new RuntimeException(e);77}78}79}808182