Path: blob/master/test/jdk/javax/swing/JOptionPane/8139213/OptionPaneTest.java
41153 views
/*1* Copyright (c) 2016, 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 813921327* @summary Mac OS Aqua X LAF: JOptionPane truncates the first button28* @run main OptionPaneTest29*/30import java.awt.Component;31import java.awt.Insets;32import java.awt.Robot;33import javax.swing.JButton;34import javax.swing.JDialog;35import javax.swing.JOptionPane;36import javax.swing.JPanel;37import javax.swing.SwingUtilities;3839public class OptionPaneTest {4041private volatile static boolean testFailed;42private static JDialog dialog;43private static Robot robot;4445public static void main(final String[] args) throws Exception {46robot = new Robot();47SwingUtilities.invokeAndWait(new Runnable() {48@Override49public void run() {50try {51JOptionPane optionPane = new JOptionPane("JOptionPane",52JOptionPane.INFORMATION_MESSAGE,53JOptionPane.DEFAULT_OPTION,54null,55new String[]{"3", "2", "1"},56null);57dialog = optionPane.createDialog("JOptionPane");58int width = 0;59Component[] comps = optionPane.getComponents();60for (Component comp : comps) {61if (comp instanceof JPanel) {62Component[] child = ((JPanel) comp).getComponents();63for (Component c : child) {64if (c instanceof JButton) {65width += c.getWidth();66}67}68}69}70Insets in = optionPane.getInsets();71width += in.left + in.right;72if (width > optionPane.getWidth()) {73testFailed = true;74}75} finally {76dialog.dispose();77}78}79});80robot.waitForIdle();81if (testFailed) {82throw new RuntimeException("Test Failed");83}84}85}868788