new TrayIcon(Image image, String tooltip) : TrayIcon « java.awt « Java by API






new TrayIcon(Image image, String tooltip)

  


import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Main {
  static Image image = Toolkit.getDefaultToolkit().getImage("images/tray.gif");

  static TrayIcon trayIcon = new TrayIcon(image, "Tester2");

  public static void main(String[] a) throws Exception {
    if (SystemTray.isSupported()) {
      SystemTray tray = SystemTray.getSystemTray();

      trayIcon.setImageAutoSize(true);
      trayIcon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          System.out.println("In here");
          trayIcon.displayMessage("Tester!", "Some action performed", TrayIcon.MessageType.INFO);
        }
      });

      try {
        tray.add(trayIcon);
      } catch (AWTException e) {
        System.err.println("TrayIcon could not be added.");
      }
    }
  }
}

   
    
  








Related examples in the same category

1.new TrayIcon(Image image)
2.new TrayIcon(Image image, String tooltip, PopupMenu popup)
3.TrayIcon: addActionListener(ActionListener listener)
4.TrayIcon: addMouseMotionListener(MouseMotionListener listener)
5.TrayIcon: displayMessage(String caption, String text, MessageType messageType)
6.TrayIcon: setActionCommand(String command)
7.TrayIcon: setImageAutoSize(boolean autosize)