List of utility methods to do Swing Menu
JMenu | createMenu(final String text) create Menu return new JMenu(text); |
JMenu | createMenu(final String text, final char mnemonic) create Menu JMenu menu = new JMenu(text); menu.setMnemonic(mnemonic); return menu; |
JMenu | createMenu(String label, int mnemonic, String description) create Menu return createMenuItem(new JMenu(label), mnemonic, description, null); |
JMenu | createMenu(String label, Object... objects) create Menu return createMenu(label, -1, objects);
|
JMenu | createMenu(String name, Object[] item, int[] accelerator, ActionListener listener) create Menu return createMenu(name, "", item, accelerator, listener); |
JMenu | createMenu(String text) create Menu JMenu menu = new JMenu(); configureTextAndMnemonic(menu, text); return menu; |
KeyStroke | createMenuKeyMask(final int aKeyStroke, final int... aMasks) Convenience method to create a key mask for menu's. int modifiers = getMenuShortcutKeyMask(); for (int aMask : aMasks) { modifiers |= aMask; return KeyStroke.getKeyStroke(aKeyStroke, modifiers); |
void | enableMenu(JTextComponent text) enable Menu final Action actionCopySelected = text.getActionMap().get(DefaultEditorKit.copyAction); final Action actionSelectAll = text.getActionMap().get(DefaultEditorKit.selectAllAction); final Action actionUnselect = text.getActionMap().get("unselect"); Action actionCopyAll = new AbstractAction("Copy All to System Clipboard") { @Override public void actionPerformed(ActionEvent e) { if (actionSelectAll != null) { actionSelectAll.actionPerformed(e); ... |
JMenuBar | findMenuBar(Container container) Traverse a container hierarchy and returns the first JMenuBar it finds. Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof JMenuBar) { return (JMenuBar) component; } else if (component instanceof Container) { JMenuBar jmb = findMenuBar((Container) component); if (jmb != null) { return jmb; ... |
MenuElement | findMenuElement(final MenuElement root, final String text) find Menu Element for (MenuElement item : root.getSubElements()) { if (item instanceof JMenu == true) { JMenu mItem = (JMenu) item; if (mItem.getSubElements().length > 0) { MenuElement elem = findMenuElement(mItem, text); if (elem != null) return elem; continue; if (item instanceof JPopupMenu == true) { JPopupMenu mItem = (JPopupMenu) item; if (mItem.getSubElements().length > 0) { MenuElement elem = findMenuElement(mItem, text); if (elem != null) return elem; continue; if (item instanceof JMenuItem == false) continue; JMenuItem mItem = (JMenuItem) item; if (mItem.getText().equals(text) == true) return mItem; return null; |