public static void changePopupMenuFont(JPopupMenu popupMenu) { for (Component comp : popupMenu.getComponents()) { if (comp instanceof JMenuItem) { comp.setFont(GUISizeHelper.menuFont); if (comp instanceof JMenu) { comp.setFont(GUISizeHelper.menuFont); for (Component subComp : ((JMenu) comp).getMenuComponents()) { subComp.setFont(GUISizeHelper.menuFont); } } } } }
private JScrollPane findScrollPane(JPopupMenu popup) { Component[] components = popup.getComponents(); for (Component component : components) { if(component instanceof JScrollPane) { return (JScrollPane) component; } } return null; }
@Override public Component[] getMenuComponents() { return (popupMenu == null) ? new Component[0] : popupMenu.getComponents(); }
JPopupMenu menu1 = new JPopupMenu(); menu1.add(new JMenuItem("Item1")); menu1.add(new JMenuItem("Item2")); countItems(menu1); JMenu menu2 = new JMenu(); menu2.add(new JMenuItem("Item1")); menu2.add(new JMenuItem("Item2")); countItems(menu2.getPopupMenu());//Use the JPopupMenu rather than the JMenu itself) private static final void countItems(JPopupMenu menu){ System.out.println("COUNT: " + menu.getComponents().length); }
private void setMenuItems() { menuItems = menu.getComponents(); if (keepVisibleIndex >= topFixedCount && keepVisibleIndex <= menuItems.length - bottomFixedCount && (keepVisibleIndex > firstIndex + scrollCount || keepVisibleIndex < firstIndex)) { firstIndex = Math.min(firstIndex, keepVisibleIndex); firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1); } if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) { refreshMenu(); } }
private void setMenuItems() { menuItems = menu.getComponents(); if (keepVisibleIndex >= topFixedCount && keepVisibleIndex <= menuItems.length - bottomFixedCount && (keepVisibleIndex > firstIndex + scrollCount || keepVisibleIndex < firstIndex)) { firstIndex = Math.min(firstIndex, keepVisibleIndex); firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1); } if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) { refreshMenu(); } }
/** * Aligns sub items in a popup menu. * * @param menu the popmenu to align */ public static void alignMenu( JPopupMenu menu) { alignComponents( menu.getComponents()); }
/** * Update the pop-up menu according to the currently selected items. * * @param rect the selected rectangle, perhaps degenerated to a point * @return true if pop-up is not empty, and thus is worth being shown */ public boolean updateMenu (Rectangle rect) { // Update interested components for (Component component : popup.getComponents()) { if (component instanceof LocationDependent) { ((LocationDependent) component).updateUserLocation(rect); } } // Check if popup is worth being displayed for (Component component : popup.getComponents()) { if (component.isVisible()) { return true; } } return false; } }
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { JPopupMenu menu = (JPopupMenu)e.getSource(); for (Component comp : menu.getComponents()) { if (comp instanceof JRadioButton) { JRadioButton rb = (JRadioButton)comp; if (rb.isSelected()) { // Figure out which one is selected... } } } }
private void setMenuItems() { menuItems = menu.getComponents(); scrollCountForScreen(); if (keepVisibleIndex >= topFixedCount && keepVisibleIndex <= menuItems.length - bottomFixedCount && (keepVisibleIndex > firstIndex + scrollCount || keepVisibleIndex < firstIndex)) { firstIndex = Math.min(firstIndex, keepVisibleIndex); firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1); } if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) { refreshMenu(); } }
public final void removeAll() { Component[] c=getPopupMenu().getComponents(); for(int i=0;i<c.length;i++) { if((c[i] instanceof JMenuItem)|| (c[i] instanceof JSeparator)) remove(c[i]); } } }
public MenuWrapper[] getSubElements(boolean skipSeparators) { Component[] components = popupMenu.getComponents(); List<MenuWrapper> elements = new ArrayList<MenuWrapper>(); for (Component component : components) { if (component instanceof JMenuItem) { elements.add(new JMenuItemWrapper((JMenuItem)component)); } else if ((component instanceof JPopupMenu.Separator)) { if (!skipSeparators) { elements.add(new SeparatorWrapper()); } } else { AssertAdapter.fail("Unexpected menu item of class: " + component.getClass()); } } return elements.toArray(new MenuWrapper[elements.size()]); }
void updateFonts(float size) { bugPopupMenu.setFont(bugPopupMenu.getFont().deriveFont(size)); mainFrame.setFontSizeHelper(size, bugPopupMenu.getComponents()); branchPopupMenu.setFont(branchPopupMenu.getFont().deriveFont(size)); mainFrame.setFontSizeHelper(size, branchPopupMenu.getComponents()); }
public void setEditMenu(JPopupMenu menu) { if (menu != null) { editMenu.removeAll(); for (Component comp : menu.getComponents()) { editMenu.add(comp); } editMenu.setEnabled(true); } else { editMenu.setEnabled(false); } }
@Override public Component[] getComponents() { if(getComponentPopupMenu()==null) { return super.getComponents(); } else { return getComponentPopupMenu().getComponents(); } }
@Override public Component[] getComponents() { if(getComponentPopupMenu()==null) { return super.getComponents(); } else { return getComponentPopupMenu().getComponents(); } }
public void enableMenus(boolean driverAvailable,int logLevel,boolean cyberDebug) { searchMenu.setEnabled(driverAvailable); Component[] items = searchMenu.getPopupMenu().getComponents(); for (int i=0;i < items.length;i++) items[i].setEnabled(driverAvailable); loggerMenu.setEnabled(driverAvailable); items = loggerMenu.getPopupMenu().getComponents(); for (int i=0;i < items.length;i++) items[i].setEnabled(driverAvailable); if (driverAvailable){ ((JRadioButtonMenuItem)items[logLevel>0?logLevel+1:0]).setSelected(true); } cyberMenu.setEnabled(driverAvailable); items = cyberMenu.getPopupMenu().getComponents(); for (int i=0;i < items.length;i++) items[i].setEnabled(driverAvailable); if (driverAvailable){ if (cyberDebug) ((JRadioButtonMenuItem)items[0]).setSelected(true); else ((JRadioButtonMenuItem)items[1]).setSelected(true); } }
protected void rebuildPopup() { log.debug("start rebuild"); try { for (Component c : ui.popup.getComponents()) { if (c instanceof JRadioButtonMenuItem) { JRadioButtonMenuItem b = (JRadioButtonMenuItem) c; Locale l = (Locale) b.getClientProperty("locale"); String text = ui.isShowPopupText() ? ui.renderer.getSafeText(l) : null; Icon icon = ui.isShowPopupIcon() ? ui.renderer.getSafeIcon(l) : null; b.setIcon(icon); b.setText(text); log.debug("text=" + text); log.debug("icon=" + icon); } } } finally { ui.popup.invalidate(); } }
protected void rebuildPopup() { log.debug("start rebuild"); try { for (Component c : ui.popup.getComponents()) { if (c instanceof JRadioButtonMenuItem) { JRadioButtonMenuItem b = (JRadioButtonMenuItem) c; Locale l = (Locale) b.getClientProperty("locale"); String text = ui.isShowPopupText() ? ui.renderer.getSafeText(l) : null; Icon icon = ui.isShowPopupIcon() ? ui.renderer.getSafeIcon(l) : null; b.setIcon(icon); b.setText(text); log.debug("text=" + text); log.debug("icon=" + icon); } } } finally { ui.popup.invalidate(); } }
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { JPopupMenu loggerPopup = loggerMenu.getPopupMenu(); JPopupMenu cyberPopup = cyberMenu.getPopupMenu(); if (e.getSource()==loggerPopup){ int logLevel = Mediator.getDriverProxy().getLogLevel(); Component[] items = loggerPopup.getComponents(); ((JRadioButtonMenuItem)items[logLevel>0?logLevel+1:0]).setSelected(true); } else if (e.getSource()==cyberPopup){ boolean cyberDebug = Mediator.getDriverProxy().getCyberDebug(); Component[] items = cyberPopup.getComponents(); if (cyberDebug) ((JRadioButtonMenuItem)items[0]).setSelected(true); else ((JRadioButtonMenuItem)items[1]).setSelected(true); } }