javax.swing.JPopupMenu.getComponents()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中javax.swing.JPopupMenu.getComponents()方法的一些代码示例,展示了JPopupMenu.getComponents()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPopupMenu.getComponents()方法的具体详情如下:
包路径:javax.swing.JPopupMenu
类名称:JPopupMenu
方法名:getComponents

JPopupMenu.getComponents介绍

暂无

代码示例

代码示例来源:origin: magefree/mage

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);
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_http

private JScrollPane findScrollPane(JPopupMenu popup) {
  Component[] components = popup.getComponents();
  for (Component component : components) {
    if(component instanceof JScrollPane) {
      return (JScrollPane) component;
    }
  }
  return null;
}

代码示例来源:origin: edu.toronto.cs.medsavant/medsavant-client

@Override
public Component[] getMenuComponents() {
  return (popupMenu == null) ? new Component[0] : popupMenu.getComponents();
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: MegaMek/megamek

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();
 }
}

代码示例来源:origin: org.apache.jmeter/jorphan

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();
  }
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

/**
 * Aligns sub items in a popup menu.
 * 
 * @param menu the popmenu to align
 */
public static void alignMenu( JPopupMenu menu) {
  alignComponents( menu.getComponents());
}

代码示例来源:origin: Audiveris/audiveris

/**
   * 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;
  }
}

代码示例来源:origin: stackoverflow.com

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...
      }
    }
  }
}

代码示例来源:origin: GoldenGnu/jeveassets

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();
  }
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

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]);
  }
 }
}

代码示例来源:origin: UISpec4J/UISpec4J

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()]);
}

代码示例来源:origin: com.google.code.findbugs/findbugs

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());
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core

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);
  }
}

代码示例来源:origin: org.orbisgis/orbisgis-view

@Override
public Component[] getComponents() {
    if(getComponentPopupMenu()==null) {
        return super.getComponents();
    } else {
        return getComponentPopupMenu().getComponents();
    }
}

代码示例来源:origin: orbisgis/orbisgis

@Override
public Component[] getComponents() {
    if(getComponentPopupMenu()==null) {
        return super.getComponents();
    } else {
        return getComponentPopupMenu().getComponents();
    }
}

代码示例来源:origin: apache/felix

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);
  }
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-widgets

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();
  }
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-widgets-i18n

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();
  }
}

代码示例来源:origin: apache/felix

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);            
  }
    
}

相关文章

JPopupMenu类方法