-7

I want to display a tray notification using Java like the notifications that comes out in windows when disk space is low, there is no antivirus software etc. enter image description here

Exactly like this.

Kusum Adhikari
  • 210
  • 3
  • 13
  • 1
    [Java System Tray Tutorial](http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html) – Crazenezz Aug 24 '12 at 04:09
  • 1
    seems this is the same you are looking for, http://stackoverflow.com/questions/3240415/how-to-create-a-notification-in-swing – Sajith Aug 24 '12 at 04:10
  • I am not looking for that mentioned here. I am trying just to display popup for some time and disappear. I am isn't it possible without manually creating frames and adding components... – Kusum Adhikari Aug 24 '12 at 04:21

2 Answers2

5

See this -> http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html

Anuj Kulkarni
  • 2,261
  • 5
  • 32
  • 42
4

I'm thinking maybe you should have a look at TrayIcon.displayMessage

The only other way I know to achieve what you want, is via JNI

EventQueue.invokeLater(new Runnable() {
    @Override
    public void run() {

        Image img = null;
        try {
            img = ImageIO.read(new File("..."));
        } catch (IOException e) {
            e.printStackTrace();
        }
        TrayIcon ti = new TrayIcon(img, "Tooltip");
        try {
            // You need to add it to the system tray first
            SystemTray.getSystemTray().add(ti);
        } catch (AWTException ex) {
          ex.printStackTrace();
        }
        ti.displayMessage("Low Disk Space", "Diskspace is very low",
                MessageType.WARNING);

    }

});
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366