Path: blob/master/test/jdk/javax/swing/JMenuItem/6438430/bug6438430.java
41153 views
/*1* Copyright (c) 2012, 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* @bug 643843026* @summary Tests that submenu title doesn't overlap with submenu indicator27* in JPopupMenu28* @author Mikhail Lapshin29* @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel bug643843030* @run main/othervm -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel bug643843031*/3233import javax.swing.JMenuItem;34import javax.swing.JMenu;35import javax.swing.JCheckBoxMenuItem;3637public class bug6438430 {38public static void main(String[] args) {39JMenu subMenu1 = new JMenu("Long-titled Sub Menu");40subMenu1.add(new JMenuItem("SubMenu Item"));41JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");4243JMenu menu1 = new JMenu("It works always");44menu1.add(checkBoxMenuItem1);45menu1.add(subMenu1);4647// Simulate DefaultMenuLayout calls.48// The latest traversed menu item must be the widest.49checkBoxMenuItem1.getPreferredSize();50int width1 = subMenu1.getPreferredSize().width;51System.out.println("width1 = " + width1);525354JMenu subMenu2 = new JMenu("Long-titled Sub Menu");55subMenu2.add(new JMenuItem("SubMenu Item"));56JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");5758JMenu menu2 = new JMenu("It did not work before the fix");59menu2.add(subMenu2);60menu2.add(checkBoxMenuItem2);6162// Simulate DefaultMenuLayout calls.63// The latest traversed menu item must be the widest.64subMenu2.getPreferredSize();65int width2 = checkBoxMenuItem2.getPreferredSize().width;66System.out.println("width2 = " + width2);6768if (width1 != width2) {69throw new RuntimeException( "Submenu title and submenu indicator " +70"overlap on JMenuItem!" );71}7273System.out.println("Test passed");74}75}767778