List of utility methods to do JPopupMenu
JMenuItem | addMenuItem(JPopupMenu menu, Action action) add Menu Item JMenuItem item = menu.add(action);
configureMenuItem(item, action);
return item;
|
void | addMenuItems(JPopupMenu menu, JComponent... items) add Menu Items for (JComponent item : items) { if (item == null) { menu.addSeparator(); } else { menu.add(item); |
KeyStroke | addOption(JPopupMenu popupMenu, String text, String key, ActionListener actionListener) add Option JMenuItem option = new JMenuItem(text); KeyStroke keyStroke = KeyStroke.getKeyStroke(key); option.setAccelerator(keyStroke); option.addActionListener(actionListener); popupMenu.add(option); return keyStroke; |
void | addPopup(Component component, final JPopupMenu popup) add Popup component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { ... |
void | addPopup(Component component, final JPopupMenu popup) Add the specified pop-up menu the specified component. component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) showMenu(e); public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) showMenu(e); ... |
void | addPopup(final Component c, final JPopupMenu m) add Popup c.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) m.show(c, e.getX(), e.getY()); }); |
void | addSeparatorIfNecessary(JPopupMenu popup) Adds a separator to the popup menu if there are menu items on it already. int count = popup.getComponentCount(); if (count > 0 && !(popup.getComponent(count - 1) instanceof JSeparator)) { popup.addSeparator(); |
void | addSeparatorIfNecessary(JPopupMenu popup) add Separator If Necessary int count = popup.getComponentCount(); if ((count > 0) && (!(popup.getComponent(count - 1) instanceof JSeparator))) popup.addSeparator(); |
boolean | addSeparatorIfNeeded(JPopupMenu popupMenu) Appends a separator to the end of the menu if it exists at least one non separator menu component immediately before and if there isn't, already, a separator at the end of the menu. final int menuComponentCount = popupMenu.getComponentCount(); if (menuComponentCount == 0) { return false; final Component lastMenuComponent = popupMenu.getComponent(menuComponentCount - 1); if (isPopupMenuSeparator(lastMenuComponent)) { return false; popupMenu.addSeparator(); return true; |
void | applyDefaultProperties(final JPopupMenu comp) Sets default background and foreground color as well as a default font for the specified component. if (comp == null) { return; applyProperties(comp, "PopupMenu.background", "PopupMenu.foreground", "PopupMenu.font"); |