系统托盘Java

时间:2012-08-24 04:04:37

标签: java user-interface

我希望使用Java显示托盘通知,例如当磁盘空间不足时,Windows中出现的通知,没有防病毒软件等。 enter image description here

正是这样。

2 个答案:

答案 0 :(得分:5)

答案 1 :(得分:4)

我想也许你应该看看TrayIcon.displayMessage

我知道实现你想要的唯一另一种方式是通过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);

    }

});