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

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

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

JPopupMenu.add介绍

暂无

代码示例

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

protected void showPopup(CategoryNode node, int x, int y) {
 JPopupMenu popup = new JPopupMenu();
 popup.setSize(150, 400);
 //
 // Configure the Popup
 //
 if (node.getParent() == null) {
  popup.add(createRemoveMenuItem());
  popup.addSeparator();
 }
 popup.add(createSelectDescendantsMenuItem(node));
 popup.add(createUnselectDescendantsMenuItem(node));
 popup.addSeparator();
 popup.add(createExpandMenuItem(node));
 popup.add(createCollapseMenuItem(node));
 popup.addSeparator();
 popup.add(createPropertiesMenuItem(node));
 popup.show(_renderer, x, y);
}

代码示例来源:origin: deathmarine/Luyten

public FileSaver(JProgressBar bar, JLabel label) {
  this.bar = bar;
  this.label = label;
  final JPopupMenu menu = new JPopupMenu("Cancel");
  final JMenuItem item = new JMenuItem("Cancel");
  item.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent arg0) {
      setCancel(true);
    }
  });
  menu.add(item);
  this.label.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent ev) {
      if (SwingUtilities.isRightMouseButton(ev) && isExtracting())
        menu.show(ev.getComponent(), ev.getX(), ev.getY());
    }
  });
}

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

final JPopupMenu popup = new JPopupMenu();
popup.add(new JMenuItem(new AbstractAction("Option 1") {
  public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(frame, "Option 1 selected");
popup.add(new JMenuItem(new AbstractAction("Option 2") {
  public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(frame, "Option 2 selected");
button.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    popup.show(e.getComponent(), e.getX(), e.getY());

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

@Override
public void mouseClicked(MouseEvent e) {
  if (SwingUtilities.isRightMouseButton(e)) {
    Component componentSource = (Component) e.getSource();
    JPopupMenu menu = new JPopupMenu();
    for (int position = 0 ; position < MediatorGui.menubar().getMenuView().getMenuComponentCount() ; position++) {
      // Fix #35348: SerializationException on clone()
      try {
        JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorGui.menubar().getMenuView().getMenuComponent(position));
        menu.add(itemMenu);
        
        final int positionFinal = position;
        itemMenu.addActionListener(actionEvent -> MediatorGui.tabManagers().setSelectedIndex(positionFinal));
      } catch (SerializationException ex) {
        LOGGER.error(ex, ex);
      }
    }
    menu.show(componentSource, e.getX(), e.getY());
    
    menu.setLocation(
      ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
      ? e.getXOnScreen() - menu.getWidth()
      : e.getXOnScreen(),
      e.getYOnScreen()
    );
  }
}

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

private void addPopupMenuCardPanel() {
  JMenuItem menuItem;
  menuItem = new JMenuItem("Hide this card");
  popupMenuCardPanel.add(menuItem);
  // Hide Card
  menuItem.addActionListener(e -> hideThisCard(cardIdPopupMenu));
  // popupMenuCardPanel.addSeparator();
}

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

final JPopupMenu popupMenu = new JPopupMenu();
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
popupMenu.add(favoriteMenuOption);

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

final JPopupMenu popupMenu = new JPopupMenu();
JMenuItem deleteItem = new JMenuItem("Delete");
deleteItem.addActionListener(new ActionListener() {
popupMenu.add(deleteItem);
table.setComponentPopupMenu(popupMenu);
frame.add(new JScrollPane(table), BorderLayout.CENTER);

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Creates the right-click popup menu. Subclasses can override this method
 * to replace or augment the popup menu returned.
 *
 * @return The popup menu.
 * @see #setPopupMenu(JPopupMenu)
 * @see #configurePopupMenu(JPopupMenu)
 * @see #createPopupMenuItem(Action)
 */
protected JPopupMenu createPopupMenu() {
  JPopupMenu menu = new JPopupMenu();
  menu.add(undoMenuItem = createPopupMenuItem(undoAction));
  menu.add(redoMenuItem = createPopupMenuItem(redoAction));
  menu.addSeparator();
  menu.add(cutMenuItem = createPopupMenuItem(cutAction));
  menu.add(createPopupMenuItem(copyAction));
  menu.add(pasteMenuItem = createPopupMenuItem(pasteAction));
  menu.add(deleteMenuItem = createPopupMenuItem(deleteAction));
  menu.addSeparator();
  menu.add(createPopupMenuItem(selectAllAction));
  return menu;
}

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

private void createAndShowSwitchPanelsMenu(final JComponent component, final AbstractButton windowButton) {
  JPopupMenu menu = new JPopupMenu();
  Component[] windows = desktopPane.getComponentsInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER);
  MagePaneMenuItem menuItem;
        });
        menu.add(menuItem);
  menu.show(component, 0, component.getHeight());

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

panelHttpProtocol.add(this.radioMethod);
final JPopupMenu popup = new JPopupMenu();
final ButtonGroup buttonGroup = new ButtonGroup();
  newMenuItem.addActionListener(actionEvent -> {
    PanelAddressBar.this.typeRequest = newMenuItem.getText();
    this.radioMethod.setText(PanelAddressBar.this.typeRequest);
  });
  popup.add(newMenuItem);
  buttonGroup.add(newMenuItem);

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

list.setSortOrder(SortOrder.ASCENDING);
final JPopupMenu popup = new JPopupMenu();
popup.add(new JScrollPane(list));
popup.setFocusable(false);
final JTextField field = new JTextField(20);
      popup.show(field, 0, field.getHeight());

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

public JMenuItem add(JMenuItem menuItem) {
  ensurePopupMenuCreated();
  return popupMenu.add(menuItem);
  popupMenu.insert(new JMenuItem(s), pos);
  JMenuItem mi = new JMenuItem(a);
  mi.setHorizontalTextPosition(JButton.TRAILING);
  mi.setVerticalTextPosition(JButton.CENTER);

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

private JPopupMenu popup = new JPopupMenu();
  popup.add(undoAction);
  popup.addSeparator();
  popup.add(cutAction);
  popup.add(copyAction);
  popup.add(pasteAction);
  popup.addSeparator();
  popup.add(selectAllAction);
    selectAllAction.setEnabled(enabled && nonempty);
    int nx = e.getX();
    popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);

代码示例来源:origin: skylot/jadx

private JPopupMenu createTabPopupMenu(final ContentPanel contentPanel) {
  JPopupMenu menu = new JPopupMenu();
    JMenuItem copyRootClassName = new JMenuItem(NLS.str("tabs.copy_class_name"));
    copyRootClassName.addActionListener(actionEvent -> copyRootClassName());
    menu.add(copyRootClassName);
    menu.addSeparator();
  JMenuItem closeTab = new JMenuItem(NLS.str("tabs.close"));
  closeTab.addActionListener(e -> closeCodePanel(contentPanel));
  menu.add(closeTab);
    JMenuItem closeOther = new JMenuItem(NLS.str("tabs.closeOthers"));
    closeOther.addActionListener(e -> {
      List<ContentPanel> contentPanels = new ArrayList<>(openTabs.values());
      for (ContentPanel panel : contentPanels) {
    menu.add(closeOther);
    JMenuItem closeAll = new JMenuItem(NLS.str("tabs.closeAll"));
    closeAll.addActionListener(e -> closeAllTabs());
    menu.add(closeAll);
    menu.addSeparator();
      item.addActionListener(e -> setSelectedComponent(cp));
      item.setIcon(node.getIcon());
      menu.add(item);

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

JList<ItemList> list = (JList<ItemList>) mouseEvent.getSource();
JPopupMenu popupMenuList = new JPopupMenu();
I18nView.addComponentForKey("LIST_IMPORT_CONFIRM_TITLE", mnImport);
I18nView.addComponentForKey("LIST_EXPORT_TITLE", mnExport);
importFileDialog.setMultiSelectionEnabled(true);
mnNew.addActionListener(new MenuActionNewValue(this.dndList));
mnImport.addActionListener(actionEvent -> {
  int choice = 0;
popupMenuList.add(mnNew);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnCut);
popupMenuList.add(mnCopy);
popupMenuList.add(mnPaste);
popupMenuList.add(mnDelete);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnSelectAll);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnImport);
popupMenuList.add(mnExport);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnRestoreDefault);

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

private void addPopupMenuPickArea() {
  int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
  KeyStroke ks9 = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
  this.getInputMap(c).put(ks9, "F9_PRESS");
  this.getActionMap().put("F9_PRESS", new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      showAgainAllHiddenCards();
    }
  });
  JMenuItem menuItem;
  menuItem = new JMenuItem("F9 - Show all hidden cards");
  popupMenuPickedArea.add(menuItem);
  // Confirm (F9)
  menuItem.addActionListener(e -> showAgainAllHiddenCards());
  // popupMenuPickedArea.addSeparator();
}

代码示例来源:origin: org.codehaus.groovy/groovy

final JPopupMenu popup = new JPopupMenu();
popup.add(loadFileAction);
jbutton.setSize(30, 30);
jbutton.addMouseListener(new MouseAdapter() {

代码示例来源:origin: camunda/camunda-bpm-platform

protected void showPopup(CategoryNode node, int x, int y) {
 JPopupMenu popup = new JPopupMenu();
 popup.setSize(150, 400);
 //
 // Configure the Popup
 //
 if (node.getParent() == null) {
  popup.add(createRemoveMenuItem());
  popup.addSeparator();
 }
 popup.add(createSelectDescendantsMenuItem(node));
 popup.add(createUnselectDescendantsMenuItem(node));
 popup.addSeparator();
 popup.add(createExpandMenuItem(node));
 popup.add(createCollapseMenuItem(node));
 popup.addSeparator();
 popup.add(createPropertiesMenuItem(node));
 popup.show(_renderer, x, y);
}

代码示例来源:origin: haraldk/TwelveMonkeys

private JPopupMenu createPopupMenu() {
  JPopupMenu popup = new JPopupMenu();
  popup.add(getActionMap().get(ZOOM_ACTUAL));
  popup.add(getActionMap().get(ZOOM_IN));
  popup.add(getActionMap().get(ZOOM_OUT));
  popup.addSeparator();
  ButtonGroup group = new ButtonGroup();
  JMenu background = new JMenu("Background");
  popup.add(background);
  ChangeBackgroundAction checkered = new ChangeBackgroundAction("Checkered", checkeredBG);
  checkered.putValue(Action.SELECTED_KEY, backgroundPaint == checkeredBG);
  addCheckBoxItem(checkered, background, group);
  background.addSeparator();
  addCheckBoxItem(new ChangeBackgroundAction("White", Color.WHITE), background, group);
  addCheckBoxItem(new ChangeBackgroundAction("Light", Color.LIGHT_GRAY), background, group);
  addCheckBoxItem(new ChangeBackgroundAction("Gray", Color.GRAY), background, group);
  addCheckBoxItem(new ChangeBackgroundAction("Dark", Color.DARK_GRAY), background, group);
  addCheckBoxItem(new ChangeBackgroundAction("Black", Color.BLACK), background, group);
  background.addSeparator();
  ChooseBackgroundAction chooseBackgroundAction = new ChooseBackgroundAction("Choose...", defaultBG != null ? defaultBG : Color.BLUE);
  chooseBackgroundAction.putValue(Action.SELECTED_KEY, backgroundPaint == defaultBG);
  addCheckBoxItem(chooseBackgroundAction, background, group);
  return popup;
}

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

private void showCardRightClickMenu(@SuppressWarnings("unused") final CardView card, MouseEvent e) {
  JPopupMenu menu = new JPopupMenu();
  JMenuItem hide = new JMenuItem("Hide");
  hide.addActionListener(e2 -> hideSelection());
  menu.add(hide);
  JMenuItem invertSelection = new JMenuItem("Invert Selection");
  invertSelection.addActionListener(e2 -> invertSelection());
  menu.add(invertSelection);
  JMenuItem chooseMatching = new JMenuItem("Choose Matching");
  chooseMatching.addActionListener(e2 -> chooseMatching());
  menu.add(chooseMatching);
  // Show 'Duplicate Selection' for FREE_BUILDING
  if (this.mode == Constants.DeckEditorMode.FREE_BUILDING) {
    JMenuItem duplicateSelection = new JMenuItem("Duplicate Selection");
    duplicateSelection.addActionListener(e2 -> duplicateSelection());
    menu.add(duplicateSelection);
  }
  menu.show(e.getComponent(), e.getX(), e.getY());
}

相关文章

JPopupMenu类方法