java.awt.PopupMenu Java Examples

The following examples show how to use java.awt.PopupMenu. 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: WTrayIconPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #3
Source File: WTrayIconPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #4
Source File: WTrayIconPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #5
Source File: WTrayIconPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #6
Source File: WTrayIconPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #7
Source File: WTrayIconPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, () -> {
        PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
        if (popup != newPopup) {
            if (popup != null) {
                popupParent.remove(popup);
            }
            if (newPopup != null) {
                popupParent.add(newPopup);
            }
            popup = newPopup;
        }
        if (popup != null) {
            WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
                                             .getPeer(popup);
            peer.show(popupParent, new Point(x, y));
        }
    });
}
 
Example #8
Source File: ThisCanvas.java    From ETL_Unicorn with Apache License 2.0 6 votes vote down vote up
public ThisCanvas(Thread threadApplet, LinkList first, NodeShow nodeView
		, PopupMenu nodeMenu, JTextPane rightBotJTextPane){
	this.setLayout(null);
	this.addMouseListener(this);
	this.addMouseMotionListener(this);
	this.start();
	this.setOpaque(false);
	this.threadApplet= threadApplet;
	this.first= first;
	this.nodeView= nodeView;
	this.nodeMenu= nodeMenu;
	this.rightBotJTextPane= rightBotJTextPane;
	chooseCheck= new ChooseCheckVPS();
	dynamicLineUpdater= new DynamicLineUpdaterVPS();
	drawArrow= new DrawArrowVPS();
	checkRange= new CheckRangeVPS();
}
 
Example #9
Source File: WTrayIconPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #10
Source File: WTrayIconPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #11
Source File: WTrayIconPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #12
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 #13
Source File: WTrayIconPeer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #14
Source File: WTrayIconPeer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #15
Source File: WTrayIconPeer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #16
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 #17
Source File: WTrayIconPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example #18
Source File: XTaskbarPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void setMenu(PopupMenu m) {
    this.menu = m;

    if (menu != null && menu.getItemCount() > 0) {
        int msize = menu.getItemCount();
        MenuItem[] items = new MenuItem[msize];
        for (int i = 0; i < msize; i++) {
            items[i] = menu.getItem(i);
        }
        setNativeMenu(items);
    } else {
        setNativeMenu(null);
    }
}
 
Example #19
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 #20
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 #21
Source File: PopupMenuLeakTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void addNotifyPopup() {
    PopupMenu menu = popupWeakReference.get().get();
    if (menu == null) {
        throw new RuntimeException("Failed: popup collected too early");
    }
    menu.addNotify();
}
 
Example #22
Source File: ComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Component.add(PopupMenu)} through queue
 */
public void add(final PopupMenu popupMenu) {
    runMapping(new MapVoidAction("add") {
        @Override
        public void map() {
            getSource().add(popupMenu);
        }
    });
}
 
Example #23
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 #24
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 #25
Source File: JTitledPanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void add(PopupMenu popup) {
    getContentPanel().add(popup);
}
 
Example #26
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 #27
Source File: CPopupMenu.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
CPopupMenu(PopupMenu target) {
    super(target);
}
 
Example #28
Source File: CPopupMenu.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
CPopupMenu(PopupMenu target) {
    super(target);
}
 
Example #29
Source File: Application.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
public PopupMenu getDockMenu() {
	return null;
}
 
Example #30
Source File: FrameworkTrayIcon.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public FrameworkTrayIcon() throws UnsupportedOperationException
{
  final StringBuffer toolTipText = new StringBuffer("Knopflerfish OSGi");
  final String servicePlatformId =
    Activator.bc.getProperty("org.osgi.provisioning.spid");
  if (null != servicePlatformId && 0 < servicePlatformId.length()) {
    toolTipText.append(" (").append(servicePlatformId).append(")");
  }

  try {
    trayIconClass = Class.forName("java.awt.TrayIcon");
    final Constructor<?> con =
      trayIconClass.getDeclaredConstructor(new Class[] { Image.class,
                                                        String.class });
    trayIcon =
      con.newInstance(new Object[] {
                                    Toolkit
                                        .getDefaultToolkit()
                                        .getImage(FrameworkTrayIcon.class
                                                      .getResource(getIconForOS())),
                                    toolTipText.toString() });

    final Method m =
      trayIconClass.getDeclaredMethod("setPopupMenu",
                                      new Class[] { PopupMenu.class });
    m.invoke(trayIcon, new Object[] { makeMenu() });

    frameworkStartLevel =
      Activator.bc.getBundle(0L).adapt(FrameworkStartLevel.class);

    updateStartLevelItems();

    Activator.bc.addFrameworkListener(new FrameworkListener() {
      public void frameworkEvent(FrameworkEvent ev)
      {
        if (FrameworkEvent.STARTLEVEL_CHANGED == ev.getType()
            || FrameworkEvent.STARTED == ev.getType()) {
          updateStartLevelItems();
        }
      }
    });
  } catch (final Exception e) {
    Activator.log.error("Failed to create FrameworkTrayIcon: " + e, e);
    throw new UnsupportedOperationException(e.getMessage());
  }
}