像在Skype中一样为java应用程序创建图标

时间:2015-02-05 20:38:05

标签: java swing awt

Skype图标很小,隐藏在桌面左下角的时钟附近。我可以使用Swing或Abstract Window Toolkit在java上创建类似我自己的应用程序吗?

1 个答案:

答案 0 :(得分:8)

是。您可以使用Java 6中引入的SystemTray类。

基本步骤是:

    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon =
            new TrayIcon(createImage("images/bulb.gif", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Populate popup menu

    trayIcon.setPopupMenu(popup);

    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        System.out.println("TrayIcon could not be added.");
    }

请参阅http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html