javax.swing.JMenuItem.addActionListener()方法的使用及代码示例

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

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

JMenuItem.addActionListener介绍

暂无

代码示例

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

protected JMenuItem createPropertiesMenuItem(final CategoryNode node) {
 JMenuItem result = new JMenuItem("Properties");
 result.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   showPropertiesDialog(node);
  }
 });
 return result;
}

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

protected JMenuItem createConfigureReset() {
 JMenuItem result = new JMenuItem("Reset");
 result.setMnemonic('r');
 result.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   resetConfiguration();
  }
 });
 return result;
}

代码示例来源:origin: kevin-wayne/algs4

private static JMenuBar createMenuBar() {
  JMenuBar menuBar = new JMenuBar();
  JMenu menu = new JMenu("File");
  menuBar.add(menu);
  JMenuItem menuItem1 = new JMenuItem(" Save...   ");
  menuItem1.addActionListener(std);
  menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
              Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
  menu.add(menuItem1);
  return menuBar;
}

代码示例来源: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: magefree/mage

public void initCardAreaPopup() {
  final JPopupMenu menu = new JPopupMenu();
  final JMenuItem hideSelected = new JMenuItem("Hide selected");
  hideSelected.addActionListener(e -> hideSelection());
  menu.add(hideSelected);
  JMenuItem showAll = new JMenuItem("Show all");
  showAll.addActionListener(e -> showAll());
  menu.add(showAll);
  JMenu sortMenu = new JMenu("Sort by...");
  final Map<Sort, JMenuItem> sortMenuItems = new LinkedHashMap<>();
  for (final Sort sort : Sort.values()) {
    JMenuItem subSort = new JCheckBoxMenuItem(sort.getText());
    sortMenuItems.put(sort, subSort);
    subSort.addActionListener(e -> {
      cardSort = sort;
      resort();
    });
    sortMenu.add(subSort);
  sortMenu.add(new JPopupMenu.Separator());
  final JCheckBoxMenuItem separateButton = new JCheckBoxMenuItem("Separate creatures");
  separateButton.addActionListener(e -> {

代码示例来源:origin: wiztools/rest-client

JMenuItem jmi_open_req = new JMenuItem("Open Request", RCFileView.REQUEST_ICON);
jmi_open_req.setMnemonic(KeyEvent.VK_O);
jmi_open_req.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
jmi_open_req.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
JMenuItem jmi_open_res = new JMenuItem("Open Response", RCFileView.RESPONSE_ICON);
jmi_open_res.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
JMenuItem jmi_open_archive = new JMenuItem("Open Req-Res Archive", RCFileView.ARCHIVE_ICON);
jmi_open_archive.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
jmi_save_req.setMnemonic(KeyEvent.VK_Q);
jmi_save_req.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
jmi_save_req.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
jmi_save_res.setMnemonic(KeyEvent.VK_S);
jmi_save_res.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {

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

private void addSaveOptionsTo(JMenu menu) {
  JMenuItem saveItem;
  for (int i = 0; i < RENDERER_SETS.length; i++) {
    saveItem = new JMenuItem("Save as " + RENDERER_SETS[i][0]);
    saveItem.addActionListener(new SaveListener((CPDRenderer) RENDERER_SETS[i][1]));
    menu.add(saveItem);
  }
}

代码示例来源: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: 4thline/cling

menuItem = new JMenu(entry.getKey().getDetails().getFriendlyName());
  for (int i = 0; i < SUPPORTED_INSTANCES; i++) {
    final int instanceId = i;
    JMenuItem instanceItem = new JMenuItem("Instance: " + i);
    instanceItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        presenter.onSendToMediaRenderer(
  menuItem = new JMenuItem(
      entry.getKey().getDetails().getFriendlyName() + " (Not Compatible)"
  );
JMenuItem noRenderersItem = new JMenuItem("No MediaRenderers found...");
noRenderersItem.setEnabled(false);
menuItems.add(noRenderersItem);

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

menuBarVendor.add(comboMenuVendor);
  itemRadioVendor.addActionListener(actionEvent -> {
    xmlModel = vendor.instance().getXmlModel();
    this.changeVendor();
  comboMenuVendor.add(itemRadioVendor);
  groupVendor.add(itemRadioVendor);

代码示例来源: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: kevin-wayne/algs4

private JMenuBar createMenuBar() {
  JMenuBar menuBar = new JMenuBar();
  JMenu menu = new JMenu("File");
  menuBar.add(menu);
  JMenuItem menuItem1 = new JMenuItem(" Save...   ");
  menuItem1.addActionListener(this);
  menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
              Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
  menu.add(menuItem1);
  return menuBar;
}

代码示例来源: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();
      final String clsName = node.makeLongString();
      JMenuItem item = new JMenuItem(clsName);
      item.addActionListener(e -> setSelectedComponent(cp));
      item.setIcon(node.getIcon());
      menu.add(item);

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

protected JMenuItem createNoLogLevelsMenuItem() {
 JMenuItem result = new JMenuItem("Hide all LogLevels");
 result.setMnemonic('h');
 result.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   selectAllLogLevels(false);
   _table.getFilteredLogTableModel().refresh();
   updateStatusLabel();
  }
 });
 return result;
}

代码示例来源:origin: i2p/i2p.i2p

browserLauncher = new JMenuItem(_t("Launch I2P Browser"));
  browserLauncher.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent arg0) {
JMenu desktopguiConfigurationLauncher = new JMenu(_t("Configure I2P System Tray"));
JMenuItem configSubmenu = new JMenuItem(_t("Disable"));
configSubmenu.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
  restartItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent arg0) {
stopItem.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
  restartItem2.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent arg0) {
stopItem2.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
cancelItem.addActionListener(new ActionListener() {
  @Override

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

@Override
public void menuSelected(MenuEvent menuEvent) {
  recentFiles.removeAll();
  File openFile = wrapper.getOpenFile();
  String currentFile = openFile == null ? "" : openFile.getAbsolutePath();
  for (final String file : settings.getRecentFiles()) {
    if (file.equals(currentFile)) {
      continue;
    }
    JMenuItem menuItem = new JMenuItem(file);
    recentFiles.add(menuItem);
    menuItem.addActionListener(e -> openFile(new File(file)));
  }
  if (recentFiles.getItemCount() == 0) {
    recentFiles.add(new JMenuItem(NLS.str("menu.no_recent_files")));
  }
}

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

protected JMenuItem createCollapseMenuItem(final CategoryNode node) {
 JMenuItem result = new JMenuItem("Collapse All Descendant Categories");
 result.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   collapseDescendants(node);
  }
 });
 return result;
}

代码示例来源: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: log4j/log4j

/**
 * Creates a Most Recently Used file list to be
 * displayed in the File menu
 */
protected void createMRUFileListMI(JMenu menu) {
 String[] files = _mruFileManager.getMRUFileList();
 if (files != null) {
  menu.addSeparator();
  for (int i = 0; i < files.length; i++) {
   JMenuItem result = new JMenuItem((i + 1) + " " + files[i]);
   result.setMnemonic(i + 1);
   result.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
     requestOpenMRU(e);
    }
   });
   menu.add(result);
  }
 }
}

代码示例来源:origin: igniterealtime/Smack

JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Message");
menuItem.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
menuItem = new JMenuItem("IQ Get");
menuItem.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
menuItem = new JMenuItem("IQ Set");
menuItem.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
menuItem = new JMenuItem("Presence");
menuItem.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
menuItem = new JMenuItem("Send");
menuItem.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
menuItem = new JMenuItem("Clear");
menuItem.addActionListener(new ActionListener() {
  @Override

相关文章

JMenuItem类方法