List of usage examples for java.awt TrayIcon TrayIcon
public TrayIcon(Image image, String tooltip, PopupMenu popup)
From source file:Main.java
License:asdf
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;// w w w . jav a2 s.c om } SystemTray tray = SystemTray.getSystemTray(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("trayIcon.jpg"); PopupMenu menu = new PopupMenu(); MenuItem messageItem = new MenuItem("Show Message"); messageItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("asdf"); } }); menu.add(messageItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(closeItem); TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu); icon.setImageAutoSize(true); tray.add(icon); }
From source file:Main.java
License:asdf
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;// www . ja v a 2 s . c om } SystemTray tray = SystemTray.getSystemTray(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("trayIcon.jpg"); PopupMenu menu = new PopupMenu(); MenuItem messageItem = new MenuItem("Show Message"); messageItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("asdf"); } }); menu.add(messageItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(closeItem); TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu); icon.setImageAutoSize(true); icon.setToolTip("tooltip"); tray.add(icon); }
From source file:Main.java
License:asdf
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//from www . j a v a 2 s . c om } SystemTray tray = SystemTray.getSystemTray(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("trayIcon.jpg"); PopupMenu menu = new PopupMenu(); MenuItem messageItem = new MenuItem("Show Message"); messageItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("asdf"); } }); menu.add(messageItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(closeItem); TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu); icon.setImageAutoSize(true); image = toolkit.getImage("anotherImage.jpg"); icon.setImage(image); tray.add(icon); }
From source file:SystemTrayDemo.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//ww w . j ava 2 s . c o m } SystemTray tray = SystemTray.getSystemTray(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("trayIcon.jpg"); PopupMenu menu = new PopupMenu(); MenuItem messageItem = new MenuItem("Show Message"); messageItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "www.java2s.com"); } }); menu.add(messageItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(closeItem); TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu); icon.setImageAutoSize(true); tray.add(icon); }
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;//www.j a v a 2s . com } 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;/* ww w .j av a 2 s . c o m*/ } SystemTray tray = SystemTray.getSystemTray(); 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); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2", popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); tray.add(ti); }
From source file:SystemTrayDemo2.java
public static void main(String[] args) { if (!SystemTray.isSupported()) { return;//from w w w . j a va2 s .c o m } SystemTray tray = SystemTray.getSystemTray(); 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); try { PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Goodbye"); System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2", popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml; ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml; mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); tray.add(ti); } catch (AWTException e) { System.out.println(e.getMessage()); return; } }
From source file:SystemTrayTest.java
public static void main(String[] args) { final TrayIcon trayIcon; if (!SystemTray.isSupported()) { System.err.println("System tray is not supported."); return;/*from w w w .j a v a2s . c om*/ } SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit().getImage("cookie.png"); PopupMenu popup = new PopupMenu(); MenuItem exitItem = new MenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); popup.add(exitItem); trayIcon = new TrayIcon(image, "Your Fortune", popup); trayIcon.setImageAutoSize(true); trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage("How do I turn this off?", "Right-click on the fortune cookie and select Exit.", TrayIcon.MessageType.INFO); } }); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); return; } final List<String> fortunes = readFortunes(); Timer timer = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent e) { int index = (int) (fortunes.size() * Math.random()); trayIcon.displayMessage("Your Fortune", fortunes.get(index), TrayIcon.MessageType.INFO); } }); timer.start(); }
From source file:SysTray.java
public void installSystemTray() throws Exception { PopupMenu menu = new PopupMenu(); MenuItem exit = new MenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0);//ww w .j ava 2 s. c o m } }); menu.add(exit); TrayIcon icon = new TrayIcon(getImage(), "Java application as a tray icon", menu); icon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Hi!"); } }); SystemTray.getSystemTray().add(icon); Thread.sleep(3000); icon.displayMessage("Attention", "Please click here", TrayIcon.MessageType.WARNING); }
From source file:com.sec.ose.osi.ui.frm.tray.JTrayIconApp.java
private void initTray() { Image image = new ImageIcon(WindowUtil.class.getResource("icon.png")).getImage(); mTrayIcon = new TrayIcon(image, mTrayTitle, createPopupMenu(BEFORE_LOGIN_STATE)); mTrayIcon.setImageAutoSize(true);// w w w . ja v a 2 s.c om mTrayIcon.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent e) { log.debug("mousePressed()"); int state = 0; currentFrame = UISharedData.getInstance().getCurrentFrame(); if (currentFrame == null) return; if (currentFrame.getClass().equals(JFrmLogin.class)) { state = BEFORE_LOGIN_STATE; } else { state = AFTER_LOGIN_STATE; } if (SwingUtilities.isRightMouseButton(e)) { mTrayIcon.setPopupMenu(createPopupMenu(state)); } if (e.getClickCount() >= DOUBLE_CLICK && !e.isConsumed()) { currentFrame.setVisible(true); } } }); try { mSystemTray.add(mTrayIcon); } catch (AWTException e1) { log.warn(e1.getMessage()); } }