javax.swing.JMenuItem Java Examples

The following examples show how to use javax.swing.JMenuItem. 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: HubsMenu.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private void rebuild(Store<HubModel> hubs, JMenu menu) {
   menu.removeAll();
   menu.add(registerHub);
   menu.add(registerHubLegacy);
   menu.add(reloadHub);
   menu.addSeparator();
   menu.add(decodeHubInfo);
   menu.addSeparator();

   if(hubs.size() == 0) {
      JMenuItem emptyMenu = new JMenuItem("Account has no hubs");
      emptyMenu.setEnabled(false);
      menu.add(emptyMenu);
   }
   else {
      for(HubModel hub: hubs.values()) {
         menu.add(new HubMenu(hub));
      }
   }
}
 
Example #2
Source File: JPopupMenuOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Pushes menu.
 *
 * @param choosers Array of choosers to find menuItems to push.
 * @return Last pushed JMenuItem.
 * @throws TimeoutExpiredException
 */
public JMenuItem pushMenu(final ComponentChooser[] choosers) {
    return ((JMenuItem) produceTimeRestricted(new Action<Object, Void>() {
        @Override
        public Object launch(Void obj) {
            //TDB 1.5 menu workaround
            getQueueTool().waitEmpty();
            Object result = driver.pushMenu(JPopupMenuOperator.this,
                    JMenuOperator.converChoosers(choosers));
            getQueueTool().waitEmpty();
            return result;
        }

        @Override
        public String getDescription() {
            return JMenuOperator.createDescription(choosers);
        }

        @Override
        public String toString() {
            return "JPopupMenuOperator.pushMenu.ComponentChooser{description = " + getDescription() + '}';
        }
    }, "JMenuOperator.PushMenuTimeout"));
}
 
Example #3
Source File: NbEditorKit.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override JMenuItem getPopupMenuItem(JTextComponent target) {
    String menuText = org.openide.util.NbBundle.getBundle (NbEditorKit.class).
        getString("Menu/View/CodeFolds");
    JMenu menu = new JMenu(menuText);
    Mnemonics.setLocalizedText(menu, menuText);
    setAddSeparatorBeforeNextAction(false);
    addAction(target, menu, BaseKit.collapseFoldAction);
    addAction(target, menu, BaseKit.expandFoldAction);
    setAddSeparatorBeforeNextAction(true);
    addAction(target, menu, BaseKit.collapseAllFoldsAction);
    addAction(target, menu, BaseKit.expandAllFoldsAction);
    // this is a hack, which assumes a certain action name from editor.fold.ui
    // if the action does not exist, nothing will be added to the menu.
    addAction(target, menu, "collapse-fold-tree"); // NOI18N
    addAction(target, menu, "expand-fold-tree"); // NOI18N
    // By default add separator before next actions (can be overriden if unwanted)
    setAddSeparatorBeforeNextAction(true);
    if (target != null) addAdditionalItems(target, menu);
    return menu;
}
 
Example #4
Source File: QuickActionMenu.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add an item to pay arrears on the given goods type.
 *
 * @param goodsType The {@code GoodsType} to pay arrears on.
 */
private void addPayArrears(final GoodsType goodsType) {
    final InGameController igc = freeColClient.getInGameController();

    JMenuItem menuItem = Utility.localizedMenuItem("payArrears");
    menuItem.addActionListener((ActionEvent ae) -> {
            igc.payArrears(goodsType);
            // FIXME: fix pcls so this hackery can go away
            if (parentPanel instanceof CargoPanel) {
                CargoPanel cargoPanel = (CargoPanel) parentPanel;
                cargoPanel.initialize();
            }
            parentPanel.revalidate();
        });
    this.add(menuItem);
}
 
Example #5
Source File: CslEditorKit.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target) {
    // Try to get the accelerator
    Keymap km = target.getKeymap();

    if (km != null) {
        KeyStroke[] keys = km.getKeyStrokesForAction(a);

        if ((keys != null) && (keys.length > 0)) {
            item.setAccelerator(keys[0]);
        } else if (a != null) {
            KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);

            if (ks != null) {
                item.setAccelerator(ks);
            }
        }
    }
}
 
Example #6
Source File: LayerTree.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Get a custom, context-sensitive popup menu for the selected node. */
private JPopupMenu getPopupMenu(DefaultMutableTreeNode node) {
	Object ob = node.getUserObject();
	LayerThing thing = null;
	if (ob instanceof LayerThing) {
		thing = (LayerThing)ob;
	} else {
		return null;
	}
	// context-sensitive popup
	JMenuItem[] item = thing.getPopupItems(this);
	if (0 == item.length) return null;
	JPopupMenu popup = new JPopupMenu();
	for (int i=0; i<item.length; i++) {
		if (null == item[i] || "" == item[i].getText()) popup.addSeparator();
		else popup.add(item[i]);
	}
	return popup;
}
 
Example #7
Source File: ShapeColorChooser.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e)
{
    JMenuItem source = (JMenuItem) e.getSource();
    current = ShapeSet.valueOf(source.getText());

    if (current != null) {
        banner.setText(current.getName());

        Color color = current.getColor();

        if (color != null) {
            //colorChooser.setColor(color);
            refreshBanner();
        } else {
            banner.setForeground(Color.black);
        }

        paste.setEnabled(false);
        shapes.setRange();
    } else {
        banner.setText("");
    }
}
 
Example #8
Source File: MicroarrayMenuBar.java    From chipster with MIT License 6 votes vote down vote up
private JMenuItem getLoadLocalSessionMenuItem(final boolean clear) {
	JMenuItem loadLocalSessionMenuItem = new JMenuItem();
	loadLocalSessionMenuItem.setText("Open local session...");
	if (clear) {
		loadLocalSessionMenuItem.setText("Open local session...");
		loadLocalSessionMenuItem.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
	} else {
		loadLocalSessionMenuItem.setText("Local session...");
	}
	loadLocalSessionMenuItem.addActionListener(new java.awt.event.ActionListener() {
		public void actionPerformed(java.awt.event.ActionEvent e) {
			try {
				application.loadSession(false, false, clear);
			} catch (Exception ioe) {
				application.reportException(ioe);
			}
		}
	});
	return loadLocalSessionMenuItem;
}
 
Example #9
Source File: VizPanel.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a menu item for hiding showing the neighbouring circle.
 */
protected void createDisEnableNeighCircMenuItem() {
  final String enableNeighbCirc = Messages
      .getString("Viz.EnableNeighbouringCircle");
  final String disableNeighbCirc = Messages
      .getString("Viz.DisableNeighbouringCircle");

  final JMenuItem disEnableNeighCircMenuItem = 
      new JMenuItem(controller.showNeighbouringCircle ?
          disableNeighbCirc : enableNeighbCirc);
  disEnableNeighCircMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      if (disEnableNeighCircMenuItem.getText().equals(enableNeighbCirc)) {
        disEnableNeighCircMenuItem.setText(disableNeighbCirc);
        controller.showNeighbouringCircle = true;
        controller.showNeighboursOnMouseover = true;
      } else {
        disEnableNeighCircMenuItem.setText(enableNeighbCirc);
        controller.showNeighbouringCircle = false;
        controller.showNeighboursOnMouseover = false;
      }
    }
  });
  add(glPopup, disEnableNeighCircMenuItem, ITEM_ID_ENABLE_NEIGH_CIRC);
}
 
Example #10
Source File: WhiteRabbitMain.java    From WhiteRabbit with Apache License 2.0 6 votes vote down vote up
private JMenuBar createMenuBar() {
	JMenuBar menuBar = new JMenuBar();
	JMenu helpMenu = new JMenu("Help");

	JMenuItem versionItem = new JMenuItem("White Rabbit v" +  Version.getVersion(this.getClass()));
	versionItem.setEnabled(false);
	helpMenu.add(versionItem);

	menuBar.add(helpMenu);
	JMenuItem helpItem = new JMenuItem(ACTION_CMD_HELP);
	helpItem.addActionListener(this);
	helpItem.setActionCommand(ACTION_CMD_HELP);
	helpMenu.add(helpItem);

	return menuBar;
}
 
Example #11
Source File: MapMenu.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
private JMenuItem createFlipArmsJMenuItem() {
    JMenuItem item = new JMenuItem("Flip Arms");

    item.setActionCommand(Integer.toString(myEntity.getId()));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                FiringDisplay display = (FiringDisplay) currentPanel;

                int id = Integer.parseInt(e.getActionCommand());
                display.updateFlipArms(!game.getEntity(id).getArmsFlipped());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    return item;
}
 
Example #12
Source File: InterestPointExplorerPanel.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected void addPopupMenu( final JTable table )
{
	final JPopupMenu popupMenu = new JPopupMenu();
	final JMenuItem deleteItem = new JMenuItem( "Delete" );

	deleteItem.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed( final ActionEvent e )
		{
			delete();
			System.out.println( "Right-click performed on table and choose DELETE" );
		}
	});

	popupMenu.add( deleteItem );

	table.setComponentPopupMenu( popupMenu );
}
 
Example #13
Source File: ButtonBuilders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JButton.class.getName())) {
        return new JButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBox.class.getName())) {
        return new JCheckBoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButton.class.getName())) {
        return new JRadioButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToggleButton.class.getName())) {
        return new JToggleButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBoxMenuItem.class.getName())) {
        return new JCheckBoxMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButtonMenuItem.class.getName())) {
        return new JRadioButtonMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenu.class.getName())) {
        return new JMenuBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuBar.class.getName())) {
        return new JMenuBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuItem.class.getName())) {
        return new JMenuItemBuilder(instance, heap);
    }
    return null;
}
 
Example #14
Source File: BoardsPane.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Triggered when mouse is pressed.
 *
 * @param e mouse event
 */
@Override
public void mousePressed (MouseEvent e)
{
    if (isContextWanted(e)) {
        JPopupMenu popup = new SeparablePopupMenu();

        // A title for this menu
        JMenuItem head = new JMenuItem("Boards for selection:");
        head.setHorizontalAlignment(SwingConstants.CENTER);
        head.setEnabled(false);
        popup.add(head);
        popup.addSeparator();

        for (Board board : boards) {
            JMenuItem item = new JCheckBoxMenuItem(board.getName(), board.isSelected());
            item.addItemListener(this);
            item.setToolTipText(
                    board.isSelected() ? "Deselect this board?" : "Select this board?");
            popup.add(item);
        }

        popup.show(component, e.getX(), e.getY());
    }
}
 
Example #15
Source File: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCheckPrioritiesOfIcons() {
    AbstractAction aa = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    Icon icon = ImageUtilities.loadImageIcon("org/openide/awt/TestIcon_big.png", true);
    aa.putValue(Action.SMALL_ICON, icon);
    aa.putValue("iconBase", "org/openide/awt/data/testIcon.gif");
    
    JButton b = new JButton();
    Actions.connect(b, aa);
    
    JMenuItem m = new JMenuItem();
    Actions.connect(m, aa, false);
    
    
    assertSame("Using the same icon (small" + icon, b.getIcon(), m.getIcon());
}
 
Example #16
Source File: MenuItemIconTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void createUI() throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        frame = new JFrame();
        frame.setTitle("Test");
        JMenuBar menuBar = new JMenuBar();
        ImageIcon icon = createIcon();
        menuItem = new JMenuItem("Command", icon);
        menuItem.setHorizontalTextPosition(SwingConstants.LEFT);
        menuBar.add(menuItem);
        frame.setJMenuBar(menuBar);
        frame.setPreferredSize(new Dimension(500, 500));
        frame.pack();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    });
}
 
Example #17
Source File: MenuChecker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
     * 
     * @param component
     * @return all menu items in the menu component
     */
    public static ArrayList<NbMenuItem> getMenuItemsList(JComponent component) {
        Component items[] = component.getComponents();
        
        ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
        
        for (Component menuItem : items) {
            if (menuItem instanceof JSeparator) {
//                System.out.println("adding separator");//DEBUG
                NbMenuItem separator = new NbMenuItem();
                separator.setSeparator(true);
                list.add(separator);
            } else {
                if (menuItem instanceof JMenu) {
                    NbMenuItem mitem = new NbMenuItem((JMenuItem) menuItem);
                    mitem.setName(mitem.getName());
                    mitem.setSubmenu (getMenuItemsList((JComponent)menuItem));
                    list.add(mitem);
                } else if (menuItem instanceof JMenuItem) {//if()                
                    NbMenuItem item = new NbMenuItem((JMenuItem) menuItem);
                    item.setName(item.getName());
                    list.add(item);
                } else {
                    System.out.println("getMenuItemsList unknown:" + menuItem.toString());
                }
            }
        }
        return list;
    }
 
Example #18
Source File: bug6438430.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #19
Source File: MenuChecker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static int getElementPosition(String element, MenuElement[] array) {
    int p = -1;
    for (int i = 0; i <
            array.length; i++) {
        if (element.equals(((JMenuItem) array[i]).getText())) {
            return i;
        }

    }
    return p;
}
 
Example #20
Source File: TestSetPopupMenu.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void loadBrowsersToMenu(List<String> browsers) {
    for (String browser : browsers) {
        JMenuItem menuItem = new JMenuItem(browser);
        menuItem.setActionCommand("ChangeBrowser");
        menuItem.addActionListener(actionListener);
        changeBrowser.add(menuItem);
        menuItem.setIcon(Canvas.EmptyIcon);
    }
}
 
Example #21
Source File: FilterActions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JMenuItem[] createMenuItems () {
    FiltersDescription filtersDesc = filters.getDescription();
    ArrayList menuItems = new ArrayList();
    for (int i = 0; i < filtersDesc.getFilterCount(); i++) {
        String filterName = filtersDesc.getName(i);
        JMenuItem menuItem = new JCheckBoxMenuItem(
                filtersDesc.getDisplayName(i), filters.isSelected(filterName)); 
        menuItem.addActionListener(this);
        menuItem.putClientProperty(PROP_FILTER_NAME, filterName);
        menuItems.add(menuItem);
    }
    return (JMenuItem[])menuItems.toArray(new JMenuItem[]{});
}
 
Example #22
Source File: CpmFrame.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the menu bar.
 *
 * @return the j menu bar
 */
private JMenuBar createMenuBar() {
  menuBar = new JMenuBar();

  JMenu fileMenu = new JMenu("File");
  List fileMenuItems = cpmPanel.createFileMenuItems();
  Iterator iter = fileMenuItems.iterator();
  while (iter.hasNext()) {
    fileMenu.add((JMenuItem) iter.next());
  }

  exitMenuItem = new JMenuItem("Exit");
  exitMenuItem.addActionListener(this);
  fileMenu.add(exitMenuItem);
  
  JMenu viewMenu = new JMenu("View");
  List viewMenuItems = cpmPanel.createViewMenuItems();
  iter = viewMenuItems.iterator();
  while (iter.hasNext()) {
    viewMenu.add((JMenuItem) iter.next());
  }

  JMenu helpMenu = new JMenu("Help");
  aboutMenuItem = new JMenuItem("About");
  aboutMenuItem.addActionListener(this);
  helpMenuItem = new JMenuItem("Help");
  helpMenuItem.addActionListener(this);
  helpMenu.add(aboutMenuItem);
  helpMenu.add(helpMenuItem);
  menuBar.add(fileMenu);
  menuBar.add(viewMenu);
  menuBar.add(helpMenu);

  return menuBar;
}
 
Example #23
Source File: MenuSelectionManagerDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Item event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")" + newline + "    New state: "
            + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected" : "unselected");
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example #24
Source File: SetMainProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get project weakly-referenced from an item.
 *
 * @param menuItem Menu item.
 *
 * @return The project, or null if it is not set or has been
 * garbage-collected.
 */
private static Project getItemProject(JMenuItem menuItem) {
    Reference<Project> p = (Reference<Project>) menuItem.getClientProperty(PROJECT_KEY);
    if (p == null) {
        return null;
    } else {
        return p.get();
    }
}
 
Example #25
Source File: MainWindow.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Add an item to the generate lists menu.
 * 
 * @param menu Menu.
 * @param mode List to be generated.
 */
private void addItemInInternalLinks(JPopupMenu menu, PageListWorker.Mode mode) {
  JMenuItem item = Utilities.createJMenuItem(mode.getTitle(), true);
  item.setActionCommand(mode.name());
  item.addActionListener(EventHandler.create(
      ActionListener.class, this, "actionInternalLinks", "actionCommand"));
  menu.add(item);
}
 
Example #26
Source File: ActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the ButtonActionConnector is being called. The testing
 * implementation is set to "active" only for this test - so the other
 * tests should retain the behaviour like running without the
 * ButtonActionConnector.
 */
public void testButtonActionConnector() throws Exception {
    TestConnector tc = Lookup.getDefault().lookup(TestConnector.class);
    tc.setActive(true);
    Action action = new ActionsTest.TestAction();
    JButton button = new JButton();
    Actions.connect(button, action);
    assertEquals(1, tc.getConnectCalled());
    JMenuItem jmi = new JMenuItem();
    Actions.connect(jmi, action, false);
    assertEquals(3, tc.getConnectCalled());
    tc.setActive(false);
}
 
Example #27
Source File: JMenuBarOverlapping.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void prepareControls() {
    frame = new JFrame("Mixing : Dropdown Overlapping test");
    frame.setLayout(new GridLayout(0,1));
    frame.setSize(200, 200);
    frame.setVisible(true);

    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Test Menu");
    ActionListener menuListener = new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            lwClicked = true;
        }
    };

    JMenuItem item;
    menu.add(item = new JMenuItem("first"));
    item.addActionListener(menuListener);
    separator = new JSeparator();
    separator.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            spClicked = true;
        }
    });
    menu.add(separator);

    for (int i = 0; i < petStrings.length; i++) {
        menu.add(item = new JMenuItem(petStrings[i]));
        item.addActionListener(menuListener);
    }
    menuBar.add(menu);
    frame.setJMenuBar(menuBar);

    propagateAWTControls(frame);
    frame.setVisible(true);
}
 
Example #28
Source File: ETable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the menu item for setting the quick filter that filters
 * the objects using equality (or non-equality).
 */
public JMenuItem getQuickFilterEqualsItem(final int column, Object value,
        String columnName, String text, boolean equals) {
    
    String s = MessageFormat.format(text, new Object[] { columnName, value});
    JMenuItem res = new JMenuItem(s);
    int modelColumn = convertColumnIndexToModel(column);
    res.addActionListener(new EqualsQuickFilter(modelColumn, value, equals));
    return res;
}
 
Example #29
Source File: GuiMain.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static JMenu makeDeploymentsMenu(CliGuiContext cliGuiCtx) {
    JMenu metaCmdMenu = new JMenu("Deployments");
    metaCmdMenu.setMnemonic(KeyEvent.VK_D);

    JMenuItem deploy = new JMenuItem(new DeployAction(cliGuiCtx));
    deploy.setMnemonic(KeyEvent.VK_D);
    metaCmdMenu.add(deploy);

    JMenuItem unDeploy = new JMenuItem(new UndeployAction(cliGuiCtx));
    unDeploy.setMnemonic(KeyEvent.VK_U);
    metaCmdMenu.add(unDeploy);

    return metaCmdMenu;
}
 
Example #30
Source File: bug6438430.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
}