Java OS X Dock Menu

我的未来我决定 提交于 2019-12-12 16:15:05

问题


Is it possible to add items to the applications dock menu?

EDIT: 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.


回答1:


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);
}

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.




回答2:


Yes (providing I understand the question).

If your just trying to customize the Java Icon in the Dock see ... http://developer.apple.com/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html#//apple_ref/doc/uid/TP40001885-208447-TPXREF120

Point two under OSX Application Bundles section "If you add an appropriate icon, it shows the application icon in the Dock, clearly identifying your application. (Otherwise, a default Java coffee cup icon appears in the Dock.)"

There is an example app (Java) for handling drag and drop events for your dock icon as well located here : http://www.devdaily.com/blog/post/jfc-swing/java-handle-drag-drop-events-mac-osx-dock-application-icon

If you want you application to automatically add it's icon during installation to the dock (possibly what you mean) you should know that there is no "official apple" way to do this as it's BAD design on OS X to force your icons into a users dock, and typically frowned upon. All MAC users i know will instantly remove your application as a result of such behavior.

That said however, you can review the system administration guides on Apple's site to see how it can be done programatically.



来源:https://stackoverflow.com/questions/1319805/java-os-x-dock-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!