Mac OS中的系统托盘(菜单附加)图标使用Java [英] System Tray (Menu Extras) icon in Mac Os using Java

查看:1229
本文介绍了Mac OS中的系统托盘(菜单附加)图标使用Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java开发桌面应用程序。我想在系统托盘上放置一个图标(带有上下文菜单)(在Mac Os中称为菜单附加功能)。 Java 6支持在Windows和Linux中执行此操作,但它在Mac OS中不起作用。



我看到一些应用程序正在执行我想要的所有三个操作系统(例如DropBox),但我不知道它们是否是用Java制作的。



我怎样才能实现这个目标?



如果在Java中不可能,是否还有其他跨平台语言能够做到这一点?



谢谢。

解决方案

AWT / Swing



根据显示如何创建菜单和图标并将其放入托盘。


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.

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.

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

这篇关于Mac OS中的系统托盘(菜单附加)图标使用Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆