Java Code Examples for java.awt.PopupMenu#add()

The following examples show how to use java.awt.PopupMenu#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownApplication.java    From proxyee-down with Apache License 2.0 6 votes vote down vote up
public void loadPopupMenu() {
  //添加右键菜单
  PopupMenu popupMenu = new PopupMenu();
  MenuItem showItem = new MenuItem(I18nUtil.getMessage("gui.tray.show"));
  showItem.addActionListener(event -> Platform.runLater(() -> loadUri("", true)));
  MenuItem setItem = new MenuItem(I18nUtil.getMessage("gui.tray.set"));
  setItem.addActionListener(event -> loadUri("/#/setting", true));
  MenuItem aboutItem = new MenuItem(I18nUtil.getMessage("gui.tray.about"));
  aboutItem.addActionListener(event -> loadUri("/#/about", true));
  MenuItem supportItem = new MenuItem(I18nUtil.getMessage("gui.tray.support"));
  supportItem.addActionListener(event -> loadUri("/#/support", true));
  MenuItem closeItem = new MenuItem(I18nUtil.getMessage("gui.tray.exit"));
  closeItem.addActionListener(event -> {
    Platform.exit();
    System.exit(0);
  });
  popupMenu.add(showItem);
  popupMenu.addSeparator();
  popupMenu.add(setItem);
  popupMenu.add(aboutItem);
  popupMenu.add(supportItem);
  popupMenu.addSeparator();
  popupMenu.add(closeItem);
  trayIcon.setPopupMenu(popupMenu);
}
 
Example 2
Source File: UpdatePopupMenu.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private PopupMenu createPopupMenu(final TrayIcon trayIcon,
        final int menuCount) {

    final PopupMenu trayIconPopupMenu = new PopupMenu();

    for (int i = 1; i <= menuCount; ++i) {
        final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);

        popupMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
                trayIcon.setPopupMenu(createPopupMenu(trayIcon,
                        menuCount + 1));
            }
        });

        trayIconPopupMenu.add(popupMenuItem);
    }

    return trayIconPopupMenu;
}
 
Example 3
Source File: StaveActionHandler.java    From jmg with GNU General Public License v2.0 6 votes vote down vote up
StaveActionHandler(Stave stave) {
theApp = stave;

      noteContextMenu = new PopupMenu();
      
      editNote = new MenuItem("Edit Note");
      editNote.addActionListener(this);
      noteContextMenu.add(editNote );       
      
      repeatNote = new MenuItem("Repeat Note");
      repeatNote.addActionListener(this);
      noteContextMenu.add(repeatNote ); 		
      
      makeRest = new MenuItem("Change to Rest");
      makeRest.addActionListener(this);
      noteContextMenu.add(makeRest);       
      
      deleteNote = new MenuItem("Delete Note");
      deleteNote.addActionListener(this);
      noteContextMenu.add(deleteNote );       
      
      theApp.add(noteContextMenu);
  }
 
Example 4
Source File: Manager.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private PopupMenu createPopupMenu() {
    PopupMenu menu = new PopupMenu(getString("Server") + " "
            + Metadata.getApplicationName());
    menu.add(createStart());
    menu.add(createStop());
    menu.addSeparator();
    menu.add(createRestart());
    menu.addSeparator();
    menu.add(createPreferences());
    menu.addSeparator();
    menu.add(createExit());
    return menu;
}
 
Example 5
Source File: Boot.java    From MakeLobbiesGreatAgain with MIT License 5 votes vote down vote up
public static void setupTray() throws AWTException {
	final SystemTray tray = SystemTray.getSystemTray();
	final PopupMenu popup = new PopupMenu();
	final MenuItem info = new MenuItem();
	final MenuItem exit = new MenuItem();
	final TrayIcon trayIcon = new TrayIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), "MLGA", popup);
	try {
		InputStream is = FileUtil.localResource("icon.png");
		trayIcon.setImage(ImageIO.read(is));
		is.close();
	} catch (IOException e1) {
		e1.printStackTrace();
	}

	info.addActionListener(e -> {
		String message = "Double-Click to lock/unlock the overlay for dragging";
		JOptionPane.showMessageDialog(null, message, "Information", JOptionPane.INFORMATION_MESSAGE);
	});

	exit.addActionListener(e -> {
		running = false;
		tray.remove(trayIcon);
		ui.close();
		System.out.println("Terminated UI...");
		System.out.println("Cleaning up system resources. Could take a while...");
		handle.close();
		System.out.println("Killed handle.");
		System.exit(0);
	});
	info.setLabel("Help");
	exit.setLabel("Exit");
	popup.add(info);
	popup.add(exit);
	tray.add(trayIcon);
}
 
Example 6
Source File: TrayController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private void createComponents() {
    startedImage = createImage("/images/subsonic-started-16.png");
    stoppedImage = createImage("/images/subsonic-stopped-16.png");

    PopupMenu menu = new PopupMenu();
    menu.add(createMenuItem(openAction));
    menu.add(createMenuItem(controlPanelAction));
    menu.addSeparator();
    menu.add(createMenuItem(hideAction));

    trayIcon = new TrayIcon(stoppedImage, "Subsonic Music Streamer", menu);
}
 
Example 7
Source File: JTrayMenu.java    From PeerWasp with MIT License 5 votes vote down vote up
public PopupMenu create(boolean isUserLoggedIn) {
	root = new PopupMenu();

	if (isUserLoggedIn) {
		root.add(createRootFolderMenu());
		// root.add(createRecentFilesMenu()); // TODO: implement additional feature.
		root.addSeparator();
		root.add(createSettingsMenu());
		root.addSeparator();
	}
	root.add(createActivityMenu());
	root.add(createQuitMenu());

	return root;
}
 
Example 8
Source File: POELevelFx.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
private void addTrayIcon() throws AWTException {
    final TrayIcon trayIcon = new TrayIcon(new ImageIcon(getClass().getResource("/icons/The_Explorer_card_art.png")).getImage(), "Path of Leveling");

    // Create a pop-up menu components
    final PopupMenu popup = new PopupMenu();
    final MenuItem shutdownItem = new MenuItem("Exit");
    final MenuItem settingsItem = new MenuItem("Settings");

    //Add components to pop-up menu
    popup.add(settingsItem);
    popup.add(shutdownItem);

    trayIcon.setPopupMenu(popup);
    trayIcon.setImageAutoSize(true); //So the icon auto-sizes

    SystemTray.getSystemTray().add(trayIcon);

    trayIcon.addMouseListener(new MouseAdapter() {
        @Override public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() == java.awt.event.MouseEvent.BUTTON1) { //Left click on tray icon (single click !)
                Platform.runLater(() -> {
                    //code to show things...
                });
            }
        }
    });

    shutdownItem.addActionListener(evnt -> {
        //code to exit the program
        //save stuff
        if(saveBuildsToMemory()){
            System.out.println("Successfully saved checkpoint");
        }else{
            System.out.println("Checkpoint save failed");
        }
        try {
                GlobalScreen.unregisterNativeHook();
        } catch (NativeHookException e1) {
                e1.printStackTrace();
        }
        System.exit(20);
    });

    settingsItem.addActionListener(evnt -> {
        //code to exit the program
        //save stuff
        if(controller!=null){
            controller.settings_event();
        }
    });
}
 
Example 9
Source File: GUISample.java    From ETL_Unicorn with Apache License 2.0 4 votes vote down vote up
private void CreatMap() throws IOException {
	w= 1446- 130;
	h= 820- 110;
	updateRelatedLine= new UpdateRelatedLineVPS();
	getContentPane().setLayout(null);
	UIManager.put("SplitPaneUI", "org.LYG.GUI.platForm.UnicornSplitPaneUI");
	UIManager.put("ScrollBarUI", "org.LYG.GUI.platForm.UnicornScrollBarUI");
	UIManager.put("TreeUI", "org.LYG.GUI.platForm.UnicornTreeUI");
	currentNodeName= new String("");
	first= new LinkList();
	nodeInfo= new NodeInfo();
	nodeView= new NodeShow(this.tableData_old, this.text);
	nodeView.tree.setBackground(Color.white);
	nodeView.setBounds(10, 168, 137, 222);
	nodeProject= new NodeProject();
	nodeProject.setBounds(10, 38, 137, 124);	
	mainSplitPane = new UnicornJSplitPane();
	mainSplitPane.setAutoscrolls(true);
	//mainSplitPane.setEnabled(false);//
	mainSplitPane.setBounds(10, 50, w-20, h-80);
	mainSplitPane.setVisible(true);
	getContentPane().add(mainSplitPane);
	leftSplitPane= new UnicornJSplitPane();
	leftSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
	mainSplitPane.setLeftComponent(leftSplitPane);
	leftSplitPane.setLeftComponent(nodeProject);
	leftSplitPane.setRightComponent(nodeView);
	rightSplitPane= new UnicornJSplitPane();
	rightSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
	mainSplitPane.setRightComponent(rightSplitPane);
	righttopSplitPane= new UnicornJSplitPane();
	rightSplitPane.setLeftComponent(righttopSplitPane);
	rightBotJTextPane= new JTextPane();
	rightBotJTextPane.setText("����~");
	nodeMenu= new PopupMenu();
	canvas= new ThisCanvas(threadApplet, first, nodeView, nodeMenu, rightBotJTextPane);
	canvas.setPreferredSize(new Dimension(1500,1000));
	canvas.setEnabled(true);
	righttopScrollPane= new JScrollPane();
	righttopScrollPane.setViewportView(canvas);
	righttopSplitPane.setLeftComponent(righttopScrollPane);
	rightrightScrollPane= new JScrollPane();
	righttopSplitPane.setRightComponent(nodeInfo);
	rightdownScrollPane= new JScrollPane(rightBotJTextPane);
	rightSplitPane.setRightComponent(rightdownScrollPane);
	popupMenu= new PopupMenu();
	menuItem= new MenuItem();
	menuItem.setLabel("add");
	popupMenu.add(menuItem);
	configre= new MenuItem();
	configre.setLabel("����");
	run= new MenuItem();
	run.setLabel("����");
	show= new MenuItem();
	show.setLabel("��ʾ");
	dNode= new MenuItem();
	dNode.setLabel("ɾ���ý�");
	dLine= new MenuItem();
	dLine.setLabel("ɾ������");
	nodeMenu.add(configre);
	nodeMenu.add(run);
	nodeMenu.add(show);
	nodeMenu.add(dNode);
	nodeMenu.add(dLine);  
	getContentPane().add(popupMenu);
	getContentPane().add(nodeMenu);
	engineMenu= new PopupMenu();
	load= new MenuItem();
	load.setLabel(StableData.CONFIG_LOAD);
	save= new MenuItem();
	save.setLabel(StableData.CONFIG_UPDATE);
	saveAs= new MenuItem();
	saveAs.setLabel(StableData.CONFIG_SAVE);
	delete= new MenuItem();
	delete.setLabel(StableData.CONFIG_DELETE);
	boot= new MenuItem();
	boot.setLabel(StableData.CONFIG_BOOT);
	bootETL= new MenuItem();
	bootETL.setLabel(StableData.CONFIG_BOOT_ETL);
	engineMenu.add(load);
	engineMenu.add(save);
	engineMenu.add(saveAs);
	engineMenu.add(delete);
	engineMenu.add(boot);
	engineMenu.add(bootETL);
	getContentPane().add(engineMenu);
	getContentPane().setVisible(true);
}
 
Example 10
Source File: PopupMenuLeakTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static PopupMenu createTrayIconPopupMenu() {
    final PopupMenu trayIconPopupMenu = new PopupMenu();
    final MenuItem popupMenuItem = new MenuItem("TEST!");
    trayIconPopupMenu.add(popupMenuItem);
    return trayIconPopupMenu;
}
 
Example 11
Source File: MainFrame.java    From scelight with Apache License 2.0 4 votes vote down vote up
/**
 * Installs a system tray icon.
 */
private void installTrayIcon() {
	if ( !SystemTray.isSupported() )
		return;
	
	final TrayIcon trayIcon = new TrayIcon( Icons.MY_APP_ICON.get().getImage(), Consts.APP_NAME_FULL + " is running." );
	trayIcon.setImageAutoSize( true );
	
	try {
		SystemTray.getSystemTray().add( trayIcon );
		
		this.trayIcon = trayIcon;
		
		trayIcon.addActionListener( Actions.SHOW_MAIN_FRAME );
		
		final PopupMenu popup = new PopupMenu();
		final MenuItem restoreMenuItem = new MenuItem( "Show Main Window" );
		restoreMenuItem.addActionListener( Actions.SHOW_MAIN_FRAME );
		popup.add( restoreMenuItem );
		final MenuItem hideMenuItem = new MenuItem( "Hide Main Window" );
		hideMenuItem.addActionListener( Actions.MINIMIZE_TO_TRAY );
		popup.add( hideMenuItem );
		popup.addSeparator();
		final MenuItem restoreDefPosMenuItem = new MenuItem( "Restore Main Window to defaults" );
		restoreDefPosMenuItem.addActionListener( new ActionAdapter() {
			@Override
			public void actionPerformed( final ActionEvent e ) {
				// First ensure it's visible and active:
				Actions.SHOW_MAIN_FRAME.actionPerformed( null );
				// And the default position:
				Actions.RESTORE_DEF_WIN_POSITION.actionPerformed( null );
			}
		} );
		popup.add( restoreDefPosMenuItem );
		popup.addSeparator();
		final MenuItem exitMenuItem = new MenuItem( "Exit" );
		exitMenuItem.addActionListener( Actions.EXIT );
		popup.add( exitMenuItem );
		trayIcon.setPopupMenu( popup );
		
		Actions.MINIMIZE_TO_TRAY.setEnabled( true );
	} catch ( final AWTException ae ) {
		Env.LOGGER.debug( "Failed to install tray icon!", ae );
	}
}
 
Example 12
Source File: AppleDock.java    From Spark with Apache License 2.0 4 votes vote down vote up
public AppleDock() {

	PopupMenu menu = new PopupMenu();

	PopupMenu statusmenu = new PopupMenu(Res.getString("menuitem.status"));

	for (Presence p : PresenceManager.getPresences()) {
	    MenuItem dd = new MenuItem(p.getStatus());
	    dd.addActionListener(this);
	    statusmenu.add(dd);
	}

	menu.add(statusmenu);

	JFrame frame = SparkManager.getMainWindow();
	frame.add(menu);

	// set dock menu
	Application app = new Application();
	app.setDockMenu(menu);

    }