List of utility methods to do Swing Menu
void | fixIconTextGap(JComponent menu) fix Icon Text Gap if (isNimbusLaF()) { Component[] components = menu.getComponents(); for (Component component : components) { if (component instanceof AbstractButton) { AbstractButton b = (AbstractButton) component; b.setIconTextGap(0); if (component instanceof JMenu) ... |
Collection | getAllMenuSubElements(MenuElement root) Returns all sub menu elements of the specified menu element. Collection<MenuElement> result = new ArrayList<MenuElement>(); for (MenuElement e : root.getSubElements()) { result.add(e); result.addAll(getAllMenuSubElements(e)); return result; |
int | getMenuFontHeight() get Menu Font Height return getFontHeight(MENU_FONT_KEY);
|
KeyStroke | getMenuKeyStroke(String stroke) get Menu Key Stroke KeyStroke key = KeyStroke.getKeyStroke(stroke); if (key != null && (key.getModifiers() & Event.CTRL_MASK) != 0) { key = KeyStroke.getKeyStroke(key.getKeyCode(), (key.getModifiers() & ~(Event.CTRL_MASK + 0x80)) | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), key.isOnKeyRelease()); return key; |
JLabel | getMenuSectionLabel(String string) get Menu Section Label JLabel l = new JLabel(string.toUpperCase()); l.setFont(new Font(l.getFont().getFamily(), Font.BOLD, 14)); l.setForeground(new Color(20, 20, 20)); return l; |
Object[] | getOperationMenu(MenuElement currentMenu, String path) get Operation Menu if (path == null || path.equals("")) return new Object[] { currentMenu, path }; ArrayList<JMenu> menus = new ArrayList<JMenu>(); if ((Object) currentMenu instanceof JMenuBar) { JMenuBar bar = (JMenuBar) currentMenu; int count = bar.getMenuCount(); for (int i = 0; i < count; i++) { menus.add(bar.getMenu(i)); ... |
List | getParsedElements(MenuElement[] elements) get Parsed Elements List<String> returnable = new ArrayList<String>(); for (MenuElement e : elements) { if (JMenuItem.class.isAssignableFrom(e.getClass())) { returnable.add(((JMenuItem) e).getText()); return returnable; |
JMenuBar | getTheMenuBar(String[][] arr) get The Menu Bar JMenuBar jmb = new JMenuBar(); JMenu jm; JMenuItem jmi; for (int i = 0; i < arr.length; i++) { jm = new JMenu(arr[i][0]); for (int j = 1; j < arr[i].length; j++) { jmi = new JMenuItem(arr[i][j]); jm.add(jmi); ... |
boolean | hasIcons(MenuElement menuElement) Return whether there are any icons at the moment. MenuElement[] elements = menuElement.getSubElements(); for (int i = 0; i < elements.length; i++) { MenuElement element = elements[i]; if (element instanceof JMenuItem && (((JMenuItem) element).getIcon() != null)) { return true; if (element instanceof JPopupMenu) { return hasIcons(element); ... |
void | installMenuKeyListener(Component cmp, MenuKeyListener keyListener) Installs the key listener in the tree of components where the argument component is included, starting in the first parent JFrame or JDialog parent. List<Component> components = getAllComponents(cmp); for (Component component : components) { if ((component instanceof JPopupMenu)) { JPopupMenu popupMenu = (JPopupMenu) component; popupMenu.addMenuKeyListener(keyListener); if ((component instanceof JMenuItem)) { JMenuItem menuItem = (JMenuItem) component; ... |