List of usage examples for java.awt SystemTray remove
public void remove(TrayIcon trayIcon)
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//from w w w . ja v a 2s .c o m } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w ww . j a va 2 s . c o m*/ } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); tray.removePropertyChangeListener("trayIcons", pcl); Thread.sleep(3000); System.exit(0); }
From source file:ActiveTray.java
public static void main(String args[]) throws Exception { if (SystemTray.isSupported() == false) { System.err.println("No system tray available"); return;//from ww w . ja v a2 s .c o m } final SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener propListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { TrayIcon oldTray[] = (TrayIcon[]) evt.getOldValue(); TrayIcon newTray[] = (TrayIcon[]) evt.getNewValue(); System.out.println(oldTray.length + " / " + newTray.length); } }; tray.addPropertyChangeListener("trayIcons", propListener); Image image = Toolkit.getDefaultToolkit().getImage("jpgIcon.jpg"); PopupMenu popup = new PopupMenu(); MenuItem item = new MenuItem("Hello, World"); final TrayIcon trayIcon = new TrayIcon(image, "Tip Text", popup); ActionListener menuActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage("Good-bye", "Cruel World", TrayIcon.MessageType.WARNING); } }; item.addActionListener(menuActionListener); popup.add(item); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); } }; trayIcon.addActionListener(actionListener); tray.add(trayIcon); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//from ww w .j a v a 2s.co m } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); TrayIcon[] icons = tray.getTrayIcons(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/* w w w. ja v a 2 s .c om*/ } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); PropertyChangeListener[] listeners = tray.getPropertyChangeListeners("trayIcons"); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:SystemTrayDemo1.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/* w w w . j a v a2s .com*/ } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { System.out.println("Old tray icon array contents: "); for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); System.out.println(); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { System.out.println("New tray icon array contents: "); for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); System.out.println(); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); g.setColor(Color.yellow); int ovalSize = (size.width < size.height) ? size.width : size.height; ovalSize /= 2; g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java
private static void setTrayMenu(TrayIcon trayIcon, MenuItem... items) { if (!SystemTray.isSupported()) { log.error("System tray is not supported"); return;/*from w ww . ja va 2 s .c o m*/ } final SystemTray systemTray = SystemTray.getSystemTray(); final PopupMenu popupMenu = new PopupMenu(); stream(items).forEach(i -> popupMenu.add(i)); trayIcon.setPopupMenu(popupMenu); try { stream(systemTray.getTrayIcons()).forEach(t -> systemTray.remove(t)); systemTray.add(trayIcon); } catch (AWTException e) { log.error("Problem set tray", e); } }
From source file:com.devbury.desktoplib.systemtray.SystemTrayApplication.java
public void start() { logSystemInfo();//from w ww.j ava 2 s .c o m try { if (!isSystemTraySupported()) { JOptionPane.showMessageDialog(null, "Could not start application. This application requires system tray support and your platform " + "does not provide this.", "System Tray Not Supported", JOptionPane.ERROR_MESSAGE); throw new RuntimeException("SystemTray is not supported"); } else { logger.debug("SystemTray is supported"); } if (applicationContext == null) { String[] locations = buildConfigLocations(); logger.debug("Creating context from " + configLocationsToString(locations)); applicationContext = new ClassPathXmlApplicationContext(locations); logger.debug("Context finished building"); } // get the TrayIconDefinition instances Map defs = applicationContext.getBeansOfType(TrayIconDefinition.class); if (defs == null || defs.isEmpty()) { throw new RuntimeException("No TrayIconDefinition instances exist in the context"); } SystemTray tray = newSystemTray(); Iterator<TrayIconDefinition> it = defs.values().iterator(); LinkedList<TrayIcon> installedIcons = new LinkedList<TrayIcon>(); while (it.hasNext()) { TrayIconDefinition def = (TrayIconDefinition) it.next(); try { TrayIcon ti = def.buildTrayIcon(); tray.add(ti); installedIcons.add(ti); } catch (Throwable t) { logger.error("Could not add TrayIconDefinition " + def); } } // get the monitor object out of the context to block on Object monitor = applicationContext.getBean("applicationShutdownService"); // if there was a splash screen shut it down SplashScreen splash = newSplashScreen(); if (splash != null) { logger.debug("Shutting down splash screen"); splash.close(); } synchronized (monitor) { monitor.wait(); } logger.debug("Application shutting down"); Iterator<TrayIcon> trayIconIt = installedIcons.iterator(); while (trayIconIt.hasNext()) { TrayIcon ti = (TrayIcon) trayIconIt.next(); tray.remove(ti); } applicationContext.close(); logger.debug("Application stopped"); } catch (Throwable t) { logger.error("Unresolved exception", t); logger.error("Application shutting down"); if (applicationContext != null) { applicationContext.close(); } logger.error("Application stopped"); } }
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;/*from w w w . j ava 2 s .c o 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: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.j ava 2s . co m } 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); } }); }