Java Code Examples for javax.swing.JMenuBar#getSubElements()
The following examples show how to use
javax.swing.JMenuBar#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: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Get MenuBar and tranfer it to ArrayList. * @param menu menu to be tranfered * @return tranfered menubar */ private static List<NbMenu> getMenuBarArrayList(JMenuBar menu) { visitMenuBar(menu); MenuElement [] elements = menu.getSubElements(); List<NbMenu> list = new ArrayList<NbMenu>(); for(int k=0; k < elements.length; k++) { // if(elements[k] instanceof JMenuItem) { // list.add(new NbMenu((JMenuItem)elements[k], null)); JMenuBarOperator menuOp = new JMenuBarOperator(menu); JMenu item = menuOp.getMenu(k); list.add(new NbMenu(item, getMenuArrayList(item))); // } /*if(elements[k] instanceof JMenuBar) { JMenuBarOperator menuOp = new JMenuBarOperator(menu); list.add(getMenuArrayList(menuOp.getMenu(0))); } */ } return list; }
Example 2
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Open all menus in menubar * @param menu to be visited */ public static void visitMenuBar(JMenuBar menu) { MenuElement[] elements = menu.getSubElements(); JMenuBarOperator op = new JMenuBarOperator(menu); for (int k = 0; k < elements.length; k++) { if (elements[k] instanceof JMenuItem) { op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true); try { op.wait(200); } catch (Exception e) { } } } }
Example 3
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Get MenuBar and tranfer it to ArrayList. * @param menu menu to be tranfered * @return tranfered menubar - !separator is ignored */ public static ArrayList<NbMenuItem> getMenuBarArrayList(JMenuBar menu) { // System.out.println("getMenuBarArrayList " + menu.getName()); visitMenuBar(menu); MenuElement[] elements = menu.getSubElements(); ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>(); for (int k = 0; k < elements.length; k++) { if (elements[k] instanceof JPopupMenu.Separator) { NbMenuItem separator = new NbMenuItem(); separator.setSeparator(true); list.add(separator); } else { if (elements[k] instanceof JMenuItem) { NbMenuItem item = new NbMenuItem((JMenuItem) elements[k]); JMenuBarOperator menuOp = new JMenuBarOperator(menu); item.setSubmenu(getMenuArrayList(menuOp.getMenu(k))); list.add(item); } } } return list; }
Example 4
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Open all menus in menubar * @param menu to be visited */ public static void visitMenuBar(JMenuBar menu) { MenuElement[] elements = menu.getSubElements(); JMenuBarOperator op = new JMenuBarOperator(menu); for (int k = 0; k < elements.length; k++) { if (elements[k] instanceof JMenuItem) { op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true); try { op.wait(200); } catch (Exception e) { } } } }
Example 5
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 6 votes |
/** Get MenuBar and tranfer it to ArrayList. * @param menu menu to be tranfered * @return tranfered menubar - !separator is ignored */ public static ArrayList<NbMenuItem> getMenuBarArrayList(JMenuBar menu) { // System.out.println("getMenuBarArrayList " + menu.getName()); visitMenuBar(menu); MenuElement[] elements = menu.getSubElements(); ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>(); for (int k = 0; k < elements.length; k++) { if (elements[k] instanceof JPopupMenu.Separator) { NbMenuItem separator = new NbMenuItem(); separator.setSeparator(true); list.add(separator); } else { if (elements[k] instanceof JMenuItem) { NbMenuItem item = new NbMenuItem((JMenuItem) elements[k]); JMenuBarOperator menuOp = new JMenuBarOperator(menu); item.setSubmenu(getMenuArrayList(menuOp.getMenu(k))); list.add(item); } } } return list; }
Example 6
Source File: MenuChecker.java From netbeans with Apache License 2.0 | 5 votes |
/** Open all menus in menubar * @param menu to be visited */ private static void visitMenuBar(JMenuBar menu) { JMenuBarOperator op = new JMenuBarOperator(menu); for (MenuElement element : menu.getSubElements()) { if (element instanceof JMenuItem) { op.pushMenu(op.parseString(((JMenuItem) element).getText(), "/"), new DefaultStringComparator(true, true)); try { op.wait(200); }catch(Exception e) {} } } }
Example 7
Source File: DefaultJMenuDriver.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static Object getSelectedElement(JMenuBar bar) { MenuElement[] subElements = bar.getSubElements(); for (MenuElement subElement : subElements) { if (subElement instanceof JMenu && ((JMenu) subElement).isPopupMenuVisible()) { return subElement; } } return null; }
Example 8
Source File: QueueJMenuDriver.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private boolean isMenuBarSelected(JMenuBar bar) { MenuElement[] subElements = bar.getSubElements(); for (MenuElement subElement : subElements) { if (subElement instanceof JMenu && ((JMenu) subElement).isPopupMenuVisible()) { return true; } } return false; }