java带图标的菜单项,Mac OS中的系统托盘(菜单附加)图标使用Java

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 for doing this in Windows and Linux, but it doesn't work in Mac Os.

I have seen some applications doing what I want in all three operating systems (e.g. DropBox), but I don't know if they are made with Java.

How can I achieve this?

If it's not possible in Java, is there any other cross-platform language able to do that?

Thanks.

解决方案

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.

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.

20a70f5591020ecdd4d5d740512baf8e.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值