List of usage examples for java.awt PopupMenu addSeparator
public void addSeparator()
From source file:misc.TrayIconDemo.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;/*w w w. j a v a 2 s . co m*/ } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("images/bulb.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip"); Menu displayMenu = new Menu("Display"); MenuItem errorItem = new MenuItem("Error"); MenuItem warningItem = new MenuItem("Warning"); MenuItem infoItem = new MenuItem("Info"); MenuItem noneItem = new MenuItem("None"); MenuItem exitItem = new MenuItem("Exit"); //Add components to popup menu popup.add(aboutItem); popup.addSeparator(); popup.add(cb1); popup.add(cb2); popup.addSeparator(); popup.add(displayMenu); displayMenu.add(errorItem); displayMenu.add(warningItem); displayMenu.add(infoItem); displayMenu.add(noneItem); popup.add(exitItem); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray"); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from the About menu item"); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(false); } } }); cb2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb2Id = e.getStateChange(); if (cb2Id == ItemEvent.SELECTED) { trayIcon.setToolTip("Sun TrayIcon"); } else { trayIcon.setToolTip(null); } } }); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem) e.getSource(); //TrayIcon.MessageType type = null; System.out.println(item.getLabel()); if ("Error".equals(item.getLabel())) { //type = TrayIcon.MessageType.ERROR; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR); } else if ("Warning".equals(item.getLabel())) { //type = TrayIcon.MessageType.WARNING; trayIcon.displayMessage("Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING); } else if ("Info".equals(item.getLabel())) { //type = TrayIcon.MessageType.INFO; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO); } else if ("None".equals(item.getLabel())) { //type = TrayIcon.MessageType.NONE; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE); } } }; errorItem.addActionListener(listener); warningItem.addActionListener(listener); infoItem.addActionListener(listener); noneItem.addActionListener(listener); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:de.tbuchloh.kiskis.gui.MainFrame.java
/** * @see de.tbuchloh.kiskis.gui.systray.IMainFrame#getPopupMenu() */// w w w . j a v a2 s . co m @Override public PopupMenu getPopupMenu() { final PopupMenu popup = new PopupMenu(); for (final Action act : _main.getPopupActions()) { if (act == null) { popup.addSeparator(); } else { final MenuItem mi = new MenuItem((String) act.getValue(Action.NAME)); mi.setEnabled(act.isEnabled()); mi.addActionListener(act); mi.setFont(new Font("Arial", Font.BOLD, 12)); popup.add(mi); } } return popup; }
From source file:application.Main.java
public void createTrayIcon(final Stage stage) { // if the operating system // supports the system tray if (SystemTray.isSupported()) { // get the SystemTray instance SystemTray tray = SystemTray.getSystemTray(); // load an image java.awt.Image image = null; try {//from ww w .j a v a 2 s. c o m // File file = new File(iconLocation); // image = ImageIO.read(file); URL urlIcon = Main.class.getResource(iconLocation); image = ImageIO.read(urlIcon); } catch (IOException ex) { System.out.println(ex); } stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent t) { hide(stage); } }); // create an action listener to listen for default action executed on the tray icon final ActionListener closeListener = new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { stage.close(); controller.terminate(); // // fileWatcher.setTerminateWatching(Boolean.TRUE); System.out.println(applicationTitle + " terminated!"); Platform.exit(); System.exit(0); } }); } }; ActionListener showListener = new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { stage.show(); } }); } }; // create a pop-up menu PopupMenu popupMenu = new PopupMenu(); MenuItem nameItem = new MenuItem(applicationTitle); nameItem.addActionListener(showListener); popupMenu.add(nameItem); popupMenu.addSeparator(); MenuItem showItem = new MenuItem("Show"); showItem.addActionListener(showListener); popupMenu.add(showItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(closeListener); popupMenu.add(closeItem); /// ... add other menu items // construct a TrayIcon, scaling the image to 16x16 (the default dimensions of a tray icon) trayIcon = new TrayIcon(image.getScaledInstance(24, 24, Image.SCALE_DEFAULT), applicationTitle, popupMenu); // set the TrayIcon properties trayIcon.addActionListener(showListener); // add the tray image try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } } }
From source file:MonitorSaurausRex.MainMenu.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;/* ww w .j ava 2 s. c o m*/ } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("Logo.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); trayIcon.setImageAutoSize(true); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Menu"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Quarantine!"); Menu displayMenu = new Menu("Actions"); MenuItem errorItem = new MenuItem("Cut Connections"); MenuItem warningItem = new MenuItem("Send Reports"); MenuItem infoItem = new MenuItem("Kill Processes"); MenuItem exitItem = new MenuItem("Exit"); //Add components to popup menu popup.add(aboutItem); popup.addSeparator(); popup.add(cb1); popup.add(cb2); popup.addSeparator(); popup.add(displayMenu); displayMenu.add(errorItem); displayMenu.add(warningItem); displayMenu.add(infoItem); popup.add(exitItem); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray"); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "MonitorSaurausRex, Designed for sec203 group project. The program was designed to be piece of software to combat Ransomware" + " in a corparate enviroment. The Project was created by Luke Barlow, Dayan Patel, Rob Shire and Sian Skiggs."); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); trayIcon.setImageAutoSize(true); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(true); } } }); cb2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb2Id = e.getStateChange(); if (cb2Id == ItemEvent.SELECTED) { trayIcon.setToolTip("Sun TrayIcon"); } else { trayIcon.setToolTip(null); } } }); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem) e.getSource(); //TrayIcon.MessageType type = null; System.out.println(item.getLabel()); if ("Error".equals(item.getLabel())) { //type = TrayIcon.MessageType.ERROR; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR); } else if ("Warning".equals(item.getLabel())) { //type = TrayIcon.MessageType.WARNING; trayIcon.displayMessage("Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING); } else if ("Info".equals(item.getLabel())) { //type = TrayIcon.MessageType.INFO; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO); } else if ("None".equals(item.getLabel())) { //type = TrayIcon.MessageType.NONE; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE); } } }; errorItem.addActionListener(listener); warningItem.addActionListener(listener); infoItem.addActionListener(listener); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:org.kootox.episodesmanager.ui.systray.EpisodesTrayIcon.java
public void create() { //Check the SystemTray support if (!SystemTray.isSupported()) { if (log.isInfoEnabled()) { log.info("SystemTray is not supported"); }/*from w w w . j a va 2 s. c o m*/ return; } if (loaded) { return; } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("systray.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem display = new MenuItem("Display"); MenuItem exit = new MenuItem("Exit"); //Add components to popup menu popup.add(display); popup.addSeparator(); popup.add(exit); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { if (log.isDebugEnabled()) { log.debug("TrayIcon could not be added."); } return; } trayIcon.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent mouseEvent) { if (mouseEvent.getButton() == MouseEvent.BUTTON1) { showHide(); } } @Override public void mousePressed(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseReleased(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseEntered(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseExited(MouseEvent mouseEvent) { //Do nothing } }); display.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showHide(); } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EpisodesManagerMainUI mainUI = EpisodesManagerContext.MAIN_UI_ENTRY_DEF.getContextValue(context); mainUI.close(); } }); loaded = true; if (log.isDebugEnabled()) { log.debug("Systray loaded"); } }
From source file:de.mycrobase.jcloudapp.Main.java
public void run() { if (!SystemTray.isSupported()) { showErrorDialog("SystemTray is unsupported!"); exit();//from ww w . jav a 2s . c om } icon = new TrayIcon(ImageNormal); icon.setImageAutoSize(true); icon.setToolTip("JCloudApp"); icon.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doUploadClipboard(); working = false; } } }); MenuItem screen = new MenuItem("Take Screenshot"); screen.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doScreenshot(); working = false; } } }); MenuItem uploadClip = new MenuItem("Upload from Clipboard"); uploadClip.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doUploadClipboard(); working = false; } } }); MenuItem upload = new MenuItem("Upload File..."); upload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doUploadFile(); working = false; } } }); MenuItem about = new MenuItem("About"); about.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doAbout(); } }); MenuItem quit = new MenuItem("Quit"); quit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doQuit(); } }); PopupMenu popupMenu = new PopupMenu(); popupMenu.add(screen); popupMenu.add(uploadClip); popupMenu.add(upload); popupMenu.add(about); popupMenu.addSeparator(); popupMenu.add(quit); icon.setPopupMenu(popupMenu); try { SystemTray.getSystemTray().add(icon); } catch (AWTException ex) { showErrorDialog("No SystemTray found!\n" + ex); exit(); } }
From source file:net.mybox.mybox.ClientGUI.java
private void placeTrayIconAWT() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//from w ww.jav a 2 s . com } final PopupMenu popup = new PopupMenu(); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem aboutItem = new MenuItem("About Mybox"); MenuItem opendirItem = new MenuItem("Open Directory"); MenuItem prefsItem = new MenuItem("Preferences"); MenuItem exitItem = new MenuItem("Quit Mybox"); //Add components to popup menu popup.add(opendirItem); popup.add(pauseItem); popup.add(syncnowItem); popup.addSeparator(); popup.add(prefsItem); popup.add(aboutItem); popup.add(connectionItem); popup.add(exitItem); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Mybox"); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { launchFileBrowser(); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //JOptionPane.showMessageDialog(null, "Mybox!"); Dialog dialog = new Dialog((ClientGUI) client.clientGui, "Mybox..."); dialog.setVisible(true); //MessageDialog dialog = new InfoMessageDialog(null, "Mybox", "... is awesome!");//ErrorMessageDialog(null, "Error", message); //dialog.setTitle("About Mybox"); //dialog.run(); //dialog.hide(); } }); prefsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //window.showAll(); ((ClientGUI) client.clientGui).setVisible(true); } }); syncnowItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { client.FullSync(); } }); opendirItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { launchFileBrowser(); } }); pauseItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (pauseItem.getLabel().equals("Pause Syncing")) { client.pause(); pauseItem.setLabel("Unpause Syncing"); } else if (pauseItem.getLabel().equals("Unpause Syncing")) { client.unpause(); pauseItem.setLabel("Pause Syncing"); } } }); connectionItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (connectionItem.getLabel().equals("Connect")) { client.start(); } else if (connectionItem.getLabel().equals("Disconnect")) { client.stop(); } } }); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:jatoo.app.App.java
private PopupMenu getTrayIconPopup() { MenuItem openItem = new MenuItem(getText("popup.open") + " " + getTitle()); openItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { show();/*from w ww . j av a 2 s .c o m*/ } }); MenuItem hideItem = new MenuItem(getText("popup.hide") + " " + getTitle()); hideItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { hide(); } }); CheckboxMenuItem hideWhenMinimizedItem = new CheckboxMenuItem(getText("popup.hide_when_minimized"), isHideWhenMinimized()); hideWhenMinimizedItem.addItemListener(new ItemListener() { public void itemStateChanged(final ItemEvent e) { setHideWhenMinimized(e.getStateChange() == ItemEvent.SELECTED); } }); MenuItem sendToBackItem = new MenuItem(getText("popup.send_to_back")); sendToBackItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { sendToBack(); } }); MenuItem closeItem = new MenuItem(getText("popup.close")); closeItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { System.exit(0); } }); // // Font font = new JMenuItem().getFont(); if (font != null) { openItem.setFont(font.deriveFont(Font.BOLD)); hideItem.setFont(font); hideWhenMinimizedItem.setFont(font); sendToBackItem.setFont(font); closeItem.setFont(font); } // // the popup PopupMenu popup = new PopupMenu(getTitle()); popup.add(openItem); popup.add(hideItem); popup.addSeparator(); popup.add(hideWhenMinimizedItem); popup.addSeparator(); popup.add(sendToBackItem); popup.addSeparator(); popup.add(closeItem); return popup; }
From source file:de.jakop.ngcalsync.application.TrayStarter.java
private void moveToTray(final Settings settings, final Application application) { final PopupMenu popup = new PopupMenu(); // Create a pop-up menu components final MenuItem syncItem = new MenuItem(UserMessage.get().MENU_ITEM_SYNCHRONIZE()); final CheckboxMenuItem schedulerItem = new CheckboxMenuItem(UserMessage.get().MENU_ITEM_SCHEDULER_ACTIVE()); final MenuItem logItem = new MenuItem(UserMessage.get().MENU_ITEM_SHOW_LOG()); final MenuItem aboutItem = new MenuItem(UserMessage.get().MENU_ITEM_ABOUT()); final MenuItem exitItem = new MenuItem(UserMessage.get().MENU_ITEM_EXIT()); // let the tray icon listen to sync events for state change application.addObserver(getTrayIcon()); //Add components to pop-up menu popup.add(syncItem);// w w w . j a v a 2 s . c om popup.add(schedulerItem); popup.add(logItem); popup.add(aboutItem); popup.addSeparator(); popup.add(exitItem); getTrayIcon().setPopupMenu(popup); application.reloadSettings(); final JFrame logWindow = createLogWindow(Level.toLevel(settings.getPopupThresholdLevel(), Level.INFO)); final JFrame aboutWindow = createAboutWindow(); final ActionListener syncActionListener = createSyncActionListener(application.getScheduler()); syncItem.addActionListener(syncActionListener); // sync also on double click getTrayIcon().addActionListener(syncActionListener); getTrayIcon().addMouseListener(createLogMouseListener(logWindow)); schedulerItem.addItemListener(createSchedulerItemListener(settings, application)); logItem.addActionListener(createLogActionListener(logWindow)); aboutItem.addActionListener(createAboutActionListener(aboutWindow)); exitItem.addActionListener(createExitActionListener(logWindow, aboutWindow)); schedulerItem.setState(settings.isSchedulerStarted()); toggleScheduler(settings.isSchedulerStarted(), settings, application); }
From source file:org.sleeksnap.ScreenSnapper.java
/** * Initialize the tray menu//www. j a v a 2 s. c o m */ private void initializeTray() { // Add uploaders from the list we loaded earlier final PopupMenu tray = new PopupMenu(); // Add the action menu tray.add(new ActionMenuItem(Language.getString("cropupload"), ScreenshotAction.CROP)); tray.add(new ActionMenuItem(Language.getString("fullupload"), ScreenshotAction.FULL)); if (Platform.isWindows() || Platform.isLinux()) { tray.add(new ActionMenuItem(Language.getString("activeupload"), ScreenshotAction.ACTIVE)); } tray.addSeparator(); tray.add(new ActionMenuItem(Language.getString("clipboardupload"), ScreenshotAction.CLIPBOARD)); tray.add(new ActionMenuItem(Language.getString("fileupload"), ScreenshotAction.FILE)); tray.addSeparator(); final MenuItem settings = new MenuItem(Language.getString("options")); settings.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (!openSettings()) { icon.displayMessage(Language.getString("error"), Language.getString("optionsOpenError"), TrayIcon.MessageType.ERROR); } } }); tray.add(settings); final MenuItem exit = new MenuItem(Language.getString("exit")); exit.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { shutdown(); } }); tray.add(exit); icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(Resources.ICON), Application.NAME + " v" + Version.getVersionString()); icon.setPopupMenu(tray); icon.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (lastUrl != null) { try { Util.openURL(new URL(lastUrl)); } catch (final Exception e1) { showException(e1, "Unable to open URL"); } } } }); try { SystemTray.getSystemTray().add(icon); } catch (final AWTException e1) { this.showException(e1); } }