Bill Nye Bill Nye - 4 years ago 831
Java Question

How to make a Windows Notification in java

In Windows 10 there is a notification thing that opens in the bottom right if the screen and i find them quite useful. I was just wondering if there is any way to create them in java? If there is an external library could you link me to it? This is what they look like

enter image description here

Answer Source

I can successfully produce this result using this very simple sample code:


import java.awt.*;
import java.awt.TrayIcon.MessageType;
import javax.swing.ImageIcon;

public class TrayIconDemo {

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

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

        //If the icon is a file
        Image image = Toolkit.getToolkit().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 resizes the image if needed
        //Set tooltip text for the tray icon
        trayIcon.setToolTip("System tray icon demo");
        trayIcon.displayMessage("Hello, World", "notification demo", MessageType.INFO);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download