Java Code Examples for javax.swing.MenuElement#getSubElements()
The following examples show how to use
javax.swing.MenuElement#getSubElements() .
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: QueueJMenuDriver.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public MenuElement launch() { MenuElement element = getMenuElement(); if (element != null) { MenuElement[] subElements = element.getSubElements(); for (MenuElement subElement : subElements) { if (((Component) subElement).isShowing() && ((Component) subElement).isEnabled() && chooser.checkPathComponent(depth, subElement)) { process(subElement); return subElement; } if (stopped) { return null; } } } return null; }
Example 2
Source File: AmidstMenu.java From amidst with GNU General Public License v3.0 | 6 votes |
@CalledOnlyBy(AmidstThread.EDT) private void runOnMenuItems(MenuElement menuElement, String[] textRepresentations, Consumer<JMenuItem> consumer) { MenuElement[] elements = menuElement.getSubElements(); if(elements != null) { for(MenuElement element : elements) { if(element instanceof JMenuItem) { for(String s : textRepresentations) { if(((JMenuItem) element).getText().equals(s)) { consumer.accept((JMenuItem) element); } } } runOnMenuItems(element, textRepresentations, consumer); } } }
Example 3
Source File: GltfBrowserApplication.java From JglTF with MIT License | 6 votes |
/** * Recursively attach the given action listener to all items in the * given menu that have a non-<code>null</code> action command * * @param menuElement The menu element * @param actionListener The action listener */ private static void attachActionListener( MenuElement menuElement, ActionListener actionListener) { if (menuElement instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem)menuElement; if (menuItem.getActionCommand() != null) { menuItem.addActionListener(actionListener); } } MenuElement[] subElements = menuElement.getSubElements(); for (MenuElement subElement : subElements) { attachActionListener(subElement, actionListener); } }
Example 4
Source File: AmidstMenu.java From amidst with GNU General Public License v3.0 | 6 votes |
@CalledOnlyBy(AmidstThread.EDT) private void runOnMenuItems(MenuElement menuElement, String[] textRepresentations, Consumer<JMenuItem> consumer) { MenuElement[] elements = menuElement.getSubElements(); if(elements != null) { for(MenuElement element : elements) { if(element instanceof JMenuItem) { for(String s : textRepresentations) { if(((JMenuItem) element).getText().equals(s)) { consumer.accept((JMenuItem) element); } } } runOnMenuItems(element, textRepresentations, consumer); } } }
Example 5
Source File: ImprovedFileChooser.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void getAllMenuItems(MenuElement menuElem, List<JMenuItem> menuItems) { if (menuElem instanceof JMenuItem) { menuItems.add((JMenuItem) menuElem); } for (MenuElement subMenuElem : menuElem.getSubElements()) { getAllMenuItems(subMenuElem, menuItems); } }
Example 6
Source File: AppleMenuDriver.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static MenuElement getSelectedElement(MenuElement bar) { MenuElement[] subElements = bar.getSubElements(); for (MenuElement subElement : subElements) { if (subElement instanceof JMenu && ((JMenu) subElement).isSelected()) { return subElement; } else if (subElement instanceof JMenuItem && ((JMenuItem) subElement).isSelected()) { return subElement; } } return null; }
Example 7
Source File: MenuKeysDispatcher.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
private static void setActionsMenu(JDialog dialog, MenuElement menu) { MenuElement[] subItems = menu.getSubElements(); InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); for (MenuElement menuElement : subItems) { if (menuElement instanceof JMenuItem) { final JMenuItem menuItem = (JMenuItem) menuElement; if (menuItem.getAccelerator() != null) { String key = "hackAction" + counter++; inputMap.put(menuItem.getAccelerator(), key); if (menuItem.getAction() == null) { dialog.getRootPane().getActionMap().put(key, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { menuItem.doClick(); } }); } else { dialog.getRootPane().getActionMap().put(key, menuItem.getAction()); } // System.out.println(key + " : " // + menuItem.getText()+ " : " // + menuItem.getActionCommand() + " : " // + menuItem.getAccelerator() + " : " // + menuItem.getAction()); } } // the original code had an else condition here, which is wrong. // JMenu is a subclass of JMenuItem, which prevents sub-menus from being traversed. if (menuElement.getSubElements().length > 0) { setActionsMenu(dialog, menuElement); } } }
Example 8
Source File: SwingUtils.java From IBC with GNU General Public License v3.0 | 4 votes |
private static void appendMenuSubElements(MenuElement element, StringBuilder builder, String indent) { for (MenuElement subItem : element.getSubElements()) { appendMenuItem((Component)subItem, builder, indent); } }
Example 9
Source File: SwingUtils.java From ib-controller with GNU General Public License v3.0 | 4 votes |
private static void appendMenuSubElements(MenuElement element, StringBuilder builder, String indent) { for (MenuElement subItem : element.getSubElements()) { appendMenuItem((Component)subItem, builder, indent); } }