Java 8 MenuItem - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 MenuItem class.

This code example shows how to use the following methods:addActionListener, setActionCommand
    /** 
     * Initializes the context menu for deleting Comments. 
     */ 
    private static void initRemoveCommentMenu() { 
 
        removeCommentItem = new MenuItem("Delete Comment");
        removeCommentItem.setActionCommand(REMOVE_COMMENT_BLOCK);
        removeCommentItem.addActionListener(rndBlockMenu);
 
        removeCommentMenu.add(removeCommentItem);
        //rndBlockMenu.add(runBlockItem); 
 
        removeCommentMenuInit = true;
    } 
 
    /** 
     * Initializes the context menu for the BlockCanvas 
     * 
     */ 
    private static void initCanvasMenu() { 
6
CodeRank
This code example shows how to use the following methods:addActionListener, setActionCommand
    index = -1;
    panel = getTextPanel();
 
    MenuBar menubar = getMenuBar();
    Menu menu = menubar.getMenu(0);
    MenuItem search = new MenuItem("Search...");
    search.setActionCommand("search");
    search.addActionListener(this);
    menu.add(search);
  } 
 
  // -- ActionListener API methods -- 
 
  public void actionPerformed(ActionEvent e) {
    if ("search".equals(e.getActionCommand())) {
      new SearchBox(this);
    } 
    else panel.actionPerformed(e);
  } 
 
6
CodeRank
This code example shows how to use the following methods:addActionListener, setShortcut
        }; 
 
        addMenu(bar, "Tools", stools);
 
        Menu     hMenu = new Menu("Help");
        MenuItem aItem = new MenuItem("About");
 
        aItem.setShortcut(new MenuShortcut('A'));
        aItem.addActionListener(this);
        hMenu.add(aItem);
 
        MenuItem hItem = new MenuItem("Help");
 
        hItem.setShortcut(new MenuShortcut('H'));
        hItem.addActionListener(this);
        hMenu.add(hItem);
 
        //bar.add(hMenu); 
        // Command above disabled only until a help display bug is fixed. 
        fMain.setMenuBar(bar);
5
CodeRank
This code example shows how to use the following methods:addItemListener, getState, getActionCommand, getLabel
 
        final CheckboxMenuItem checkboxMenuItem;
 
        public JCheckBoxMenuItemWrapper(CheckboxMenuItem checkboxMenuItem)
        { 
            super(checkboxMenuItem.getLabel(), checkboxMenuItem.getState());
 
            // keep reference on source MenuItem 
            this.checkboxMenuItem = checkboxMenuItem;
 
            setActionCommand(checkboxMenuItem.getActionCommand());
 
            checkboxMenuItem.addItemListener(this);
 
            addActionListener(this);
            addItemListener(this);
        } 
 
        @Override 
        public void actionPerformed(ActionEvent e)
5
CodeRank
This code example shows how to use the following methods:addActionListener
This code example shows how to use the following methods:addActionListener, setActionCommand
 private void installMenu(){ 
      _menuBar      = new MenuBar() ;
 
      _fileMenu     = new Menu( "File" ) ;
 
      _fileMenu.add( _fileExitItem = new MenuItem( "Exit" ) );
      _fileExitItem.addActionListener( this ) ;
      _fileExitItem.setActionCommand( "exit" ) ;
 
      _editMenu     = new Menu( "Edit" ) ;
 
      _editMenu.add( _editEditItem = new MenuItem( "Edit Topology" ) );
      _editEditItem.addActionListener( this ) ;
      _editEditItem.setActionCommand( "edit" ) ;
 
      _widthMenu     = new Menu( "Options" ) ;
 
      _menuBar.add( _fileMenu ) ;
//      _menuBar.add( _editMenu ) ; 
      _menuBar.add( _widthMenu ) ;
5
CodeRank
This code example shows how to use the following methods:addActionListener
	public static void main(String[] args) throws Exception {
		new WebSocketRemote(); 
	} 
 
	public WebSocketRemote() throws Exception {
		MenuItem quitMenuItem = new MenuItem("Quit");
		quitMenuItem.addActionListener(new ActionListener() {
			@Override 
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			} 
		}); 
 
		PopupMenu popupMenu = new PopupMenu();
		popupMenu.add(quitMenuItem);
 
		URL imageUrl = this.getClass().getClassLoader().getResource("images/icon.png");
		TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().createImage(imageUrl));
		trayIcon.setImageAutoSize(true);
		trayIcon.setToolTip("WebSocketRemote");
4
CodeRank
This code example shows how to use the following methods:addActionListener
 
		// The Help Menu... 
		hm = new Menu("Help");
		hm.add(mi = new MenuItem("About"));
		mi.addActionListener(this);
		hm.add(mi = new MenuItem("Topics"));
		mi.addActionListener(this);
		mb.add(hm);
		mb.setHelpMenu(hm);		// needed for portability (Motif, etc.).
 
		// the main window 
		cp.add(new Label("Menu Demo Window"));
		pack();
	} 
 
	/** Handle action events. */ 
	public void actionPerformed(ActionEvent evt) {
		// System.out.println("Event " + evt); 
		String cmd;
		if ((cmd = evt.getActionCommand()) == null)
4
CodeRank
This code example shows how to use the following methods:addActionListener
        public FaceButtonPopupMenu(SOCFaceButton fbutton)
        { 
          super ("JSettlers"); 
          fb = fbutton;
 
          changeFaceItem = new MenuItem(/*I*/"Change face..."/*18N*/);
          add(changeFaceItem);
          changeFaceItem.addActionListener(this);
        } 
 
        /** Show menu at this position. 
         *  
         * @param x   Mouse x-position relative to facebutton 
         * @param y   Mouse y-position relative to facebutton 
         */ 
        public void show(int x, int y)
        { 
            super.show(fb, x, y);
        } 
 
3
CodeRank
This code example shows how to use the following methods:getPeer, addNotify, getLabel
    } 
 
    @SuppressWarnings("deprecation") 
    public void addItem(MenuItem item) {
        //the current awt way of adding a separator appears to be adding an item with "-" as the label 
        if ("-".equals(item.getLabel())) {
            addSeparator(); 
        } else { 
            item.addNotify();
            jComponent.add(((SwingBaseMenuItemPeer<?, ?>) item.getPeer()).jComponent);
        } 
    } 
 
    public void delItem(int index) {
        jComponent.remove(index);
    } 
 
    public void addSeparator() { 
        jComponent.addSeparator(); 
    } 
4
CodeRank
See Code Examples for Java 8 MenuItem Methods: