List of usage examples for java.awt SystemTray getTrayIcons
public TrayIcon[] getTrayIcons()
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// w w w.ja 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: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;// w w w . j ava2 s. co 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); } }