2015-12-28 17 views
16

Windows 10'da, ekranın sağ alt köşesinde açılan bir bildirim var ve bunları oldukça kullanışlı buluyorum.Java'da Windows Bildirimi nasıl yapılır

Java'da Windows bildirimleri oluşturmanın bir yolu var mı?

screenshot

import java.awt.*; 
import java.awt.TrayIcon.MessageType; 
import java.net.MalformedURLException; 

public class TrayIconDemo { 

    public static void main(String[] args) throws AWTException, MalformedURLException { 
     if (SystemTray.isSupported()) { 
      TrayIconDemo td = new TrayIconDemo(); 
      td.displayTray(); 
     } else { 
      System.err.println("System tray not supported!"); 
     } 
    } 

    public void displayTray() throws AWTException, MalformedURLException { 
     //Obtain only one instance of the SystemTray object 
     SystemTray tray = SystemTray.getSystemTray(); 

     //If the icon is a file 
     Image image = Toolkit.getDefaultToolkit().createImage("icon.png"); 
     //Alternative (if the icon is on the classpath): 
     //Image image = Toolkit.getToolkit().createImage(getClass().getResource("icon.png")); 

     TrayIcon trayIcon = new TrayIcon(image, "Tray Demo"); 
     //Let the system resize the image if needed 
     trayIcon.setImageAutoSize(true); 
     //Set tooltip text for the tray icon 
     trayIcon.setToolTip("System tray icon demo"); 
     tray.add(trayIcon); 

     trayIcon.displayMessage("Hello, World", "notification demo", MessageType.INFO); 
    } 
} 

cevap

29

başarıyla bu çok basit örnek kodu kullanarak bu sonucu üretebilir: Bu da böyle görünüyor sınıflar. Ayrıca, bu sizin için yeni bir API ise, özel ders "How to Use the System Tray" kontrol etmek isteyebilirsiniz.

+0

Bir soru kullanarak jdk 1.8 de benim için çalışıyor, ben gördük özel png dosyaları ile diğer bildirimler var. –

+0

Mümkün gibi görünmüyor - bu, AWT'de bulunmayan bir özellik gibi gözüküyor, muhtemelen yalnızca yerel pencereler gui araç takımlarında kullanılabilir. – RAnders00

+1

Şu anda bildirim, kullanım süresinden sonra eylem merkezinden kaldırılır. Orada kalmanın bir yolu var mı? – Blaine

0

Doğru cevap Toolkit.getDefaultToolkit() Toolkit.getToolkit yerine () ben kendi dokusuna ünlem işareti koymak nasıl

İlgili konular