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