Java OS X Dock菜单 [英] Java OS X Dock Menu
问题描述
是否可以将项目添加到应用程序停靠菜单?
Is it possible to add items to the applications dock menu?
我想我想念这个问题,我不是在寻找一种将图标添加到扩展坞的方法.我要寻找的是,当您右键单击iTunes图标时,可以在菜单上获得iTunes控制(播放暂停等),我想知道如何向该菜单添加自定义项目.
I think i miss phrased the question, i am not looking for a way to add an icon to the dock. what i am looking for is, when you right click on the itunes icon you get itunes control on the menu (play pause etc) i was wondering how can i add custom items to that menu.
推荐答案
查看com.apple.eawt包.具体来说,在初始化应用程序时,请执行以下操作:
Look into the com.apple.eawt package. Specifically, when you initialize your app, do something like the following:
if (System.getProperty("os.name").startsWith("Mac OS X")) {
// only do this setup if we know this is a Mac
com.apple.eawt.Application macApp = com.apple.eawt.Application.getApplication();
java.awt.PopupMenu menu = new java.awt.PopupMenu();
// create your java.awt.MenuItem objects here
// add to menu via java.awt.Menu#add(java.awt.MenuItem)
macApp.setDockMenu(menu);
}
如果您将其作为跨平台应用程序分发,则Apple为com.apple.eawt软件包提供了带有存根的Apple Java Extensions jar,因此该代码将与非Apple JDK一起编译.
If you are distributing this as a cross-platform application, Apple provides an Apple Java Extensions jar with stubs for the com.apple.eawt package, so the code will compile with non-Apple JDKs.
这篇关于Java OS X Dock菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!