TrayIcon: setImageAutoSize(boolean autosize) : TrayIcon « java.awt « Java by API






TrayIcon: setImageAutoSize(boolean autosize)

  
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
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 {
  public static void main(String[] args)throws Exception {
    if (!SystemTray.isSupported()) {
      System.out.println("SystemTray is not supported");
      return;
    }

    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);
  }
}

   
    
  








Related examples in the same category

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