Path: blob/master/test/jdk/javax/swing/JComboBox/WindowsComboBoxSize/WindowsComboBoxSizeTest.java
41152 views
/*1* Copyright (c) 2017, 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 8179027 821311627* @requires (os.family == "windows")28* @summary JComboBox too small under Windows LAF29* @run main WindowsComboBoxSizeTest30*/3132import javax.swing.*;33import java.awt.FlowLayout;34import java.awt.Robot;3536public class WindowsComboBoxSizeTest {37private static JTextField textField;38private static JComboBox<String> comboBox;39private static JComboBox<String> comboBoxEd;40private static JFrame frame;4142public static void main(String[] args) throws Exception {43UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());4445SwingUtilities.invokeAndWait(() -> {46frame = new JFrame();47frame.getContentPane().setLayout( new FlowLayout() );4849textField = new JTextField("item 1");50frame.getContentPane().add(textField);5152comboBox = new JComboBox<>(new String[]53{"item 1", "item 2", "item 3"});54frame.getContentPane().add(comboBox);5556comboBoxEd = new JComboBox<>(new String[]57{"item 1", "item 2", "item 3"});58comboBoxEd.setEditable( true );59frame.getContentPane().add(comboBoxEd);6061frame.pack();62frame.setVisible( true );63});64Robot robot = new Robot();65robot.waitForIdle();66try {67test();68} finally {69SwingUtilities.invokeLater(frame::dispose);70}71}7273private static void test() throws Exception {74SwingUtilities.invokeAndWait(() -> {75int expected = textField.getSize().height;76if (comboBox.getSize().height != expected ) {77throw new RuntimeException(78"Wrong non-editable JComboBox height " +79comboBox.getSize().height + " expected " + expected);80}81if (comboBoxEd.getSize().height != expected ) {82throw new RuntimeException(83"Wrong editable JComboBox height " +84comboBoxEd.getSize().height + " expected " + expected);85}86});87}88}89909192