javax/swing/JMenuItem/6438430/bug6438430.java

Print this page


   1 /*























   2  * @test
   3  * @bug 6438430
   4  * @summary Tests that submenu title doesn't overlap with submenu indicator
   5  *          in JPopupMenu
   6  * @author Mikhail Lapshin
   7  * @run main bug6438430

   8  */
   9 
  10 import javax.swing.JMenuItem;
  11 import javax.swing.JMenu;
  12 import javax.swing.JCheckBoxMenuItem;
  13 
  14 public class bug6438430 {
  15     public static void main(String[] args) {
  16         JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
  17         subMenu1.add(new JMenuItem("SubMenu Item"));
  18         JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");
  19 
  20         JMenu menu1 = new JMenu("It works always");
  21         menu1.add(checkBoxMenuItem1);
  22         menu1.add(subMenu1);
  23 
  24         // Simulate DefaultMenuLayout calls.
  25         // The latest traversed menu item must be the widest.
  26         checkBoxMenuItem1.getPreferredSize();
  27         int width1 = subMenu1.getPreferredSize().width;


   1 /*
   2  * Copyright (c) 2012, 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 6438430
  27  * @summary Tests that submenu title doesn't overlap with submenu indicator
  28  *          in JPopupMenu
  29  * @author Mikhail Lapshin
  30  * @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel bug6438430
  31  * @run main/othervm -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel bug6438430
  32  */
  33 
  34 import javax.swing.JMenuItem;
  35 import javax.swing.JMenu;
  36 import javax.swing.JCheckBoxMenuItem;
  37 
  38 public class bug6438430 {
  39     public static void main(String[] args) {
  40         JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
  41         subMenu1.add(new JMenuItem("SubMenu Item"));
  42         JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");
  43 
  44         JMenu menu1 = new JMenu("It works always");
  45         menu1.add(checkBoxMenuItem1);
  46         menu1.add(subMenu1);
  47 
  48         // Simulate DefaultMenuLayout calls.
  49         // The latest traversed menu item must be the widest.
  50         checkBoxMenuItem1.getPreferredSize();
  51         int width1 = subMenu1.getPreferredSize().width;