22 Ocak 2021 Cuma

Awt SystemTray Sınıfı

Giriş
Şu satırı dahil ederiz
import java.awt.SystemTray;
displayMessage metodu
Şöyle yaparız
String toolTip = "...";

if (SystemTray.isSupported()) {
  SystemTray tray = SystemTray.getSystemTray();
  TrayIcon[] trayIcons = tray.getTrayIcons();

  for (TrayIcon trayIcon: trayIcons ) {
    if (trayIcon.getToolTip().equals(toolTip)) {
      tray.remove(trayIcon);
    }
  }

  //If the icon is a file : e.g src/main/resources/2_1.jpg
  Image image = Toolkit.getDefaultToolkit().createImage("2_1.jpg");
  //Alternative (if the icon is on the classpath):
  //Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));

  TrayIcon trayIcon = new TrayIcon(image, toolTip);
  //Let the system resize the image if needed
  trayIcon.setImageAutoSize(true);
  //Set tooltip text for the tray icon
  tray.add(trayIcon);

  trayIcon.displayMessage("...", TrayIcon.MessageType.INFO);
}

Hiç yorum yok:

Yorum Gönder