Java Code Examples for javax.swing.JMenu#getPreferredSize()
The following examples show how to use
javax.swing.JMenu#getPreferredSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bug6438430.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 2
Source File: bug6438430.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 3
Source File: bug6438430.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 4
Source File: bug6438430.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 5
Source File: bug6438430.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 6
Source File: bug6438430.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 7
Source File: bug6438430.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 8
Source File: bug6438430.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 9
Source File: bug6438430.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 10
Source File: bug6438430.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 11
Source File: bug6438430.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 12
Source File: bug6438430.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }
Example 13
Source File: bug6438430.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JMenu subMenu1 = new JMenu("Long-titled Sub Menu"); subMenu1.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox"); JMenu menu1 = new JMenu("It works always"); menu1.add(checkBoxMenuItem1); menu1.add(subMenu1); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. checkBoxMenuItem1.getPreferredSize(); int width1 = subMenu1.getPreferredSize().width; System.out.println("width1 = " + width1); JMenu subMenu2 = new JMenu("Long-titled Sub Menu"); subMenu2.add(new JMenuItem("SubMenu Item")); JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox"); JMenu menu2 = new JMenu("It did not work before the fix"); menu2.add(subMenu2); menu2.add(checkBoxMenuItem2); // Simulate DefaultMenuLayout calls. // The latest traversed menu item must be the widest. subMenu2.getPreferredSize(); int width2 = checkBoxMenuItem2.getPreferredSize().width; System.out.println("width2 = " + width2); if (width1 != width2) { throw new RuntimeException( "Submenu title and submenu indicator " + "overlap on JMenuItem!" ); } System.out.println("Test passed"); }