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

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

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

JPopupMenu.insert介绍

暂无

代码示例

代码示例来源:origin: ron190/jsql-injection

popup.insert(panelCustomMethod, popup.getComponentCount());

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

popupMenu.insert(new JMenuItem(s), pos);
popupMenu.insert(mi, pos);
return mi;
mi.setHorizontalTextPosition(JButton.TRAILING);
mi.setVerticalTextPosition(JButton.CENTER);
popupMenu.insert(mi, pos);
return mi;
popupMenu.insert(new JPopupMenu.Separator(), index);

代码示例来源:origin: com.fifesoft.rtext/fife.common

/**
 * Inserts a menu item at the specified index.
 *
 * @param item The menu item to insert.
 * @param index The index at which to add the menu item.
 * @see #addMenuItem(JMenuItem)
 * @see #addSeparator()
 * @see #removeItem(int)
 */
public void insertMenuItem(JMenuItem item, int index) {
  popupMenu.insert(item, index);
}

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

/**
 * @deprecated Use register instead
 */
public void feedPopupMenu(JPopupMenu areaMenu) {
    boolean addSeparator = areaMenu.getComponentCount() != 0;
    int customMenuCounter=0; // default position of components
    for(Action action : actions) {
        JMenuItem actionItem = new JMenuItem(action);
        areaMenu.insert(actionItem, customMenuCounter++);
    }
    if(addSeparator) {
        //Separator at the end
        areaMenu.insert(new JSeparator(),customMenuCounter++);
    }
}

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

/**
 * @deprecated Use register instead
 */
public void feedPopupMenu(JPopupMenu areaMenu) {
    boolean addSeparator = areaMenu.getComponentCount() != 0;
    int customMenuCounter=0; // default position of components
    for(Action action : actions) {
        JMenuItem actionItem = new JMenuItem(action);
        areaMenu.insert(actionItem, customMenuCounter++);
    }
    if(addSeparator) {
        //Separator at the end
        areaMenu.insert(new JSeparator(),customMenuCounter++);
    }
}

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

@Override
public void insert(String s, int pos) {
  if(pos < 0) {
    throw new IllegalArgumentException("index less than zero.");
  }
  ensurePopupMenuCreated();
  popupMenu.insert(new JMenuItem(s), pos);
}

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

@Override
public JMenuItem insert(JMenuItem mi, int pos) {
  if(pos < 0) {
    throw new IllegalArgumentException("index less than zero.");
  }
  ensurePopupMenuCreated();
  popupMenu.insert(mi, pos);
  return mi;
}

代码示例来源:origin: org.cytoscape/swing-util-api

@Override
public void addMenuSeparator(final double gravity) {
      final int index = getInsertLocation("-", gravity);
      menu.insert(new JSeparator(), index);
      final Component separator = menu.getComponent(index);
      componentGravity.put(separator, gravity);
      logger.info("Inserted menu separator with gravity: " + gravity);
}

代码示例来源:origin: org.cytoscape/swing-util-api

@Override
public void addMenuItem(final JMenuItem newMenuItem, final double gravity) {
      final int index = getInsertLocation(newMenuItem.getText(), gravity);
      menu.insert(newMenuItem, index);
      componentGravity.put(newMenuItem, gravity);
      logger.info("Inserted menu item: " + newMenuItem + " with gravity: " + gravity);
}

代码示例来源:origin: org.cytoscape/swing-util-api

@Override
public void addMenu(final JMenu newSubmenu, final double gravity) {
      final int index = getInsertLocation(newSubmenu.getText(), gravity);
      menu.insert(newSubmenu, index);
      componentGravity.put(newSubmenu, gravity);
      logger.info("Inserted menu: " + newSubmenu + " with gravity: " + gravity);
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Creates the popup menu that the user will see when they right click on a
 * component
 * @param e mouse event
 * @return popup menu  
 */
@Override
protected JPopupMenu getPopup(MouseEvent e) {
  int index = 0;
  JPopupMenu popup = super.getPopup(e);
  JMenuItem menuItem = new JMenuItem("Edit Transition");
  menuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      showEditor();
    }
  });
  popup.insert(menuItem, index++);
  popup.insert(new JPopupMenu.Separator(), index);
  return popup;
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Creates the pop up meny for a place containing the options
 * Edit place
 *
 * @param e event
 * @return the pop up menu for the place
 */
@Override
protected JPopupMenu getPopup(MouseEvent e) {
  int index = 0;
  JPopupMenu popup = super.getPopup(e);
  JMenuItem menuItem = new JMenuItem("Edit Place");
  ActionListener actionListener = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      showEditor();
    }
  };
  menuItem.addActionListener(actionListener);
  popup.insert(menuItem, index++);
  popup.insert(new JPopupMenu.Separator(), index);
  return popup;
}

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

@Override
public void insertSeparator(int index) {
  if(index < 0) {
    throw new IllegalArgumentException("index less than zero.");
  }
  ensurePopupMenuCreated();
  popupMenu.insert(new JPopupMenu.Separator(), index);
}

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

@Override
public JMenuItem insert(Action a, int pos) {
  if(pos < 0) {
    throw new IllegalArgumentException("index less than zero.");
  }
  ensurePopupMenuCreated();
  JMenuItem mi = new JMenuItem(a);
  mi.setHorizontalTextPosition(JButton.TRAILING);
  mi.setVerticalTextPosition(JButton.CENTER);
  popupMenu.insert(mi, pos);
  return mi;
}

代码示例来源:origin: org.cytoscape/swing-application-impl

@SuppressWarnings({ "unchecked", "rawtypes" })
private void addFactory(TaskFactory factory, Map props) {
  CyAction action;
  if ( props.containsKey("enableFor") )
    action = new TaskFactoryTunableAction(taskMgr, factory, props, appMgr, netViewMgr);
  else
    action = new TaskFactoryTunableAction(taskMgr, factory, props);
  final JMenuItem item = new JMenuItem(action);
  Double gravity = 10.0;
  if (props.containsKey(ServiceProperties.MENU_GRAVITY)){
    gravity = Double.valueOf(props.get(ServiceProperties.MENU_GRAVITY).toString());
  }
  
  this.actionGravityMap.put(item, gravity);
  
  popupMap.put(factory, item);
  popupActions.put(factory, action);
  int menuIndex = getMenuIndexByGravity(item);
  popup.insert(item, menuIndex);
  popup.addPopupMenuListener(action);
}

代码示例来源:origin: com.synaptix/SynaptixSwing

public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
  int count = tabPane.getComponentCount();
  for (int i = 0; i < count; i++) {
    Icon icon = tabPane.getIconAt(i);
    String text = tabPane.getTitleAt(i);
    JChevronMenuItem menuItem = new JChevronMenuItem(i, text, icon);
    menuItem.addActionListener(new MenuItemActionListener());
    if (!isExistTabRunAt(i)) {
      menuItem.setBold(true);
      chevronPopupMenu.insert(menuItem, 0);
    } else {
      chevronPopupMenu.add(menuItem);
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf

private void customizeTemplatesLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customizeTemplatesLabelMouseClicked
  String viewTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.VIEW_TEMPLATE);
  String editTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.EDIT_TEMPLATE);
  String createTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.CREATE_TEMPLATE);
  String listTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.LIST_TEMPLATE);
  String baseTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.BASE_TEMPLATE);
  String controllerTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.CONTROLLER_TEMPLATE);
  String paginationTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.PAGINATION_TEMPLATE);
  String utilTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.UTIL_TEMPLATE);
  String bundleTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.BUNDLE_TEMPLATE);
  JPopupMenu menu = new JPopupMenu();
  List<String> paths = new ArrayList<>();
  processValidPath(menu, paths, viewTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.viewTemplate"));
  processValidPath(menu, paths, editTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.editTemplate"));
  processValidPath(menu, paths, createTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.createTemplate"));
  processValidPath(menu, paths, listTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.listTemplate"));
  processValidPath(menu, paths, baseTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.baseTemplate"));
  processValidPath(menu, paths, controllerTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.controllerTemplate"));
  processValidPath(menu, paths, paginationTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.paginationTemplate"));
  processValidPath(menu, paths, utilTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.utilTemplate"));
  processValidPath(menu, paths, bundleTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.bundleTemplate"));
  menu.insert(new OpenTemplateAction(this, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.allTemplates"), paths.toArray(new String[paths.size()])), 0);
  menu.show(customizeTemplatesLabel, evt.getX(), evt.getY());
}//GEN-LAST:event_customizeTemplatesLabelMouseClicked

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

public void addMenuComponent(JMenu menu, final Component component, final int index) {
  final JPopupMenu popupMenu = menu.getPopupMenu();
  final int itemCount = popupMenu.getComponentCount();
  if(index == 0 || index < itemCount)
    popupMenu.insert(component, index);
  else {
    final Component lastMenuItem = popupMenu.getComponent(itemCount - 1);
    final boolean extraSubMenu = isExtraSubMenu(lastMenuItem);
    if (extraSubMenu || !fitsOnScreen(popupMenu, component)) {
      final JMenu submenu;
      if(extraSubMenu) {
        submenu = (JMenu) lastMenuItem;
      }
      else {
        if (component instanceof JPopupMenu.Separator)
          return;
        submenu = new JMenu("-");
        submenu.putClientProperty(EXTRA_SUBMENU, Boolean.TRUE);
        popupMenu.add(submenu);
        if(! Compat.isMacOsX())
          submenu.getPopupMenu().addPopupMenuListener(MnemonicSetter.INSTANCE);
      }
      addMenuComponent(submenu, component, submenu.getPopupMenu().getComponentCount());
    }
    else
      popupMenu.insert(component, index);
  }
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Inserts a separator at the given {@code position} if it exists a non separator menu component at the given
 * {@code position} and if there isn't, already, a separator immediately before the insert {@code position} (to prevent
 * consecutive separators).
 * 
 * @param popupMenu the pop up menu that will be processed
 * @param position the position where a separator might be inserted
 * @return {@code true} if the separator was inserted, {@code false} otherwise.
 * @see javax.swing.JPopupMenu.Separator
 */
public static boolean insertSeparatorIfNeeded(JPopupMenu popupMenu, int position) {
  final int menuComponentCount = popupMenu.getComponentCount();
  if (menuComponentCount == 0 || position <= 0 || position > menuComponentCount) {
    return false;
  }
  final Component currentComponent = popupMenu.getComponent(position);
  if (isPopupMenuSeparator(currentComponent)) {
    return false;
  }
  final Component previousComponent = popupMenu.getComponent(position - 1);
  if (isPopupMenuSeparator(previousComponent)) {
    return false;
  }
  popupMenu.insert(new JPopupMenu.Separator(), position);
  return true;
}

代码示例来源:origin: xyz.cofe/gui.swing

private void onChildInserted(int idx, MenuItem mi) {
  int subElementsCount = getPopupMenu().getSubElements().length;
  boolean append = idx < 0 || idx >= subElementsCount;
  Component miComponent = null;
  if (mi instanceof MenuSeparatorItem) {
    ObserverMenuSeparator oms = createObserverMenuSeparator();
    oms.setMenu(mi);
    miComponent = oms;
  } else if (mi instanceof MenuActionItem) {
    ObserverMenuItem omi = createObserverMenuItem();
    omi.setMenu(mi);
    miComponent = omi;
  } else if (mi instanceof MenuContainer) {
    ObserverMenuContainer omc = createObserverMenuContainer();
    omc.setMenu(mi);
    miComponent = omc;
  }
  if (miComponent != null) {
    if (append) {
      getPopupMenu().add(miComponent);
    } else {
      getPopupMenu().insert(miComponent, idx);
    }
  }
}

相关文章

JPopupMenu类方法