List of usage examples for java.awt PopupMenu PopupMenu
public PopupMenu() throws HeadlessException
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 . j a va 2s . 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) { 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;//from w w w.j a v a 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) { 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 w ww .j a va 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) { 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;//from www . j a v a 2s . 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) { 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:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*w w w .j a v a2s . c om*/ } 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:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w ww.j a v a2s . 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"); ti.setPopupMenu(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:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// ww w .ja v a2 s . com } 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"); ti.setPopupMenu(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); String tooltip = ti.getToolTip(); tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// w ww . j a va 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"); ti.setPopupMenu(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); PopupMenu popupMenu = ti.getPopupMenu(); tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// w w w . j a v 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"); ti.setPopupMenu(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); boolean bool = ti.isImageAutoSize(); tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from ww w . jav a2s . co 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"); ti.setPopupMenu(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); MouseListener[] mouseListeners = ti.getMouseListeners(); tray.add(ti); }