System Tray (Menu Extras) icon in Mac Os using Java

前端 未结 2 1206
不思量自难忘°
不思量自难忘° 2020-12-23 01:00

I\'m developing a desktop application using Java. I want to put an icon (with a contextual menu) on the system tray (called Menu Extras in Mac Os). Java 6 comes with support

相关标签:
2条回答
  • 2020-12-23 01:32

    I ported a Windows application to my Mac with little difficulty. One thing I noticed is that the icons are in full, living color (not following the Mac convention). I'll need to add a little OS-specific code to convert myself. But this is a big step up from the DLL dependent Desktop integration version from earlier iterations of Java.

    0 讨论(0)
  • 2020-12-23 01:48

    AWT / Swing

    According to documentation, OSX 10.5 update 1 and newer support TrayIcons

    TrayIcons are represented on Mac OS X using NSStatusMenus that are presented to the left of the standard system menu extras. The java.awt.Image artwork for a TrayIcon is presented in grayscale as per the Mac OS X standard for menu extras.

    TrayIcon.displayMessage() presents a small non-modal dialog positioned under the TrayIcon. The ActionListener for the TrayIcon is only fired if the "OK" button on the non-modal dialog is pressed, and not if the window is closed using the window close button.

    Multiple calls to TrayIcon.displayMessage() will dismiss prior messages and leave only the last message. If the application is not in the foreground when TrayIcon.displayMessage() is called, the application bounces its icon in the Dock. Message windows are badged with the application's icon to identify the which application triggered the notification.

    noah provided this sample:

    java.awt.SystemTray.getSystemTray().add(new java.awt.TrayIcon(java.awt.Toolkit.getDefaultToolkit().getImage("foo.png")));
    

    Note that you'll probably want to attach a menu to that icon before adding it to the tray, though.

    SWT

    According to documentation, SWT 3.3 and newer supports TrayItem icons on OSX.

    Icons placed on the system tray will now appear when running on OS X in the status bar. SWT TrayItem

    This snippet shows how to create a menu and icon and put them in the Tray.

    0 讨论(0)
提交回复
热议问题