Path: blob/master/test/jdk/javax/swing/JSpinner/WrongEditorTextFieldFont/FontByDefault.java
41153 views
/*1* Copyright (c) 2016, 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*/2223/*24* @test25* @key headful26* @bug 642105827* @summary Verify font of the text field is changed to the font of28* JSpinner if the font of text field was NOT set by the user29*/3031import java.awt.Font;32import javax.swing.JFrame;33import javax.swing.JSpinner;34import javax.swing.JSpinner.DefaultEditor;35import javax.swing.SwingUtilities;36import javax.swing.UIManager;37import javax.swing.UnsupportedLookAndFeelException;38import javax.swing.plaf.UIResource;39import static javax.swing.UIManager.getInstalledLookAndFeels;4041public class FontByDefault implements Runnable {4243public static void main(final String[] args) throws Exception {44for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {45SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));46SwingUtilities.invokeAndWait(new FontByDefault());47}48}4950@Override51public void run() {52final JFrame mainFrame = new JFrame();53try {54testDefaultFont(mainFrame);55} finally {56mainFrame.dispose();57}58}5960private static void testDefaultFont(final JFrame frame) {61frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6263JSpinner spinner = new JSpinner();64frame.add(spinner);65frame.setSize(300, 100);66frame.setVisible(true);6768final DefaultEditor editor = (DefaultEditor) spinner.getEditor();69final Font editorFont = editor.getTextField().getFont();7071/*72* Validate that the font of the text field is changed to the73* font of JSpinner if the font of text field was not set by the74* user.75*/7677if (!(editorFont instanceof UIResource)) {78throw new RuntimeException("Font must be UIResource");79}80if (!editorFont.equals(spinner.getFont())) {81throw new RuntimeException("Wrong FONT");82}83}8485private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {86try {87UIManager.setLookAndFeel(laf.getClassName());88} catch (ClassNotFoundException | InstantiationException |89UnsupportedLookAndFeelException | IllegalAccessException e) {90throw new RuntimeException(e);91}92}93}949596