从Java访问Mac OS X应用程序菜单 [英] Access Mac OS X Application Menu from Java

查看:143
本文介绍了从Java访问Mac OS X应用程序菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个专为所有平台设计的Java应用程序,但具体来说,我正在开发OS X外观和集成(我在MacBook Pro上使用NetBeans)。我想访问应用程序的菜单,即以应用程序命名的粗体菜单。我想为About和Quit项注册监听器,以及显示Preferences项。我也不介意再添加一些我自己的项目。

I'm writing a Java application designed for all platforms, but specifically, I am working on OS X appearance and integration (I use NetBeans on my MacBook Pro). I'd like to access the application's menu, i.e. the bolded menu named after the application. I want to register listeners for the About and Quit items, as well as show the Preferences item. I wouldn't mind adding a few more items of my own, too.

那么,我该怎么做?我之前的帖子提到了OSXAdapter,但是Apple的天才决定将它从库中删除(或者模糊地重命名)因为所有链接都重定向到主页面,而我所有的搜索都没有结果。我还看过 MacOSAppAdapter 课程,但我不确定如何使用它。所有导入和新类和层次结构都有点令人困惑。

So, how do I do this? I have seen previous posts refer to OSXAdapter, but the geniuses at Apple decided to remove it from their library (or rename it ambiguously) because all links redirect to the main page, and all my searching has been fruitless. I've also seen a MacOSAppAdapter class, but I am unsure how to use it. All the importing and new classes and hierarchies is bit confusing.

编辑:

这就是我所做的绑定到About,Preferences和Quit项目:

This is what I did to tie into the About, Preferences, and Quit items:

我创建了一个新类MacOSXAboutHandler,它扩展了

I made a new class, MacOSXAboutHandler, that extends

com.apple.eawt.Application

它的构造函数只是调用

setAboutHandler(AboutHandler aH)

我提供了我自己的监听器,扩展了

and I provide it with my own listener that extends

AboutHandler

在我的主课程中,我确定我是否在Mac上运行

In my main class I determine if I am running on a Mac using

System.getProperty("os.name").contains("mac")

如果这是真的,那么我只需创建一个新的MacOSXAboutHandler实例。构造函数添加了我的处理程序,每当应用程序运行(甚至在NetBeans中测试)时,单击应用程序粗体菜单上的About ...项目将执行我在AboutHandler中指定的代码。

If this is true, then I simply create a new instance of MacOSXAboutHandler. The constructor adds my handler, and whenever the application is run (or even tested within NetBeans), clicking the About... item on the application's bolded menu executes the code I specified in my AboutHandler.

对于首选项和退出也是如此,只需用适当的操作替换约的出现。所有这些处理程序都是按照任何其他Java监听程序编写的。

The same is done for preferences and quit, simply replacing occurrences of "about" with the appropriate action. All these handlers are written as any other Java listener would be.

推荐答案

您可能希望查看将您的Java应用程序带到Mac OS X 和(更重要的是)将您的Java应用程序引入Mac OS X第2部分将您的Java应用程序带到Mac OS X第3部分

You might want to have a look at Bringing your Java Application to Mac OS X and (more importantly) Bringing your Java Application to Mac OS X Part 2 and Bringing your Java Application to Mac OS X Part 3

您可能 Mac的Java系统属性参考使用

你可能想要一个看看 Apple的Java 6 Extensions API ,在我的简短阅读中,如果 com.apple.eawt.Application 并提供您需要的处理程序(例如 setAboutHandler )。

You may want to take a look at Apple's Java 6 Extensions API, from my brief reading, it would appear that you basically want to use the default instance if com.apple.eawt.Application and supply the handlers you need (such as setAboutHandler).

您可能还想阅读 Mac OS X上的Java关于,退出和首选项菜单项和事件文章,应提供更多内容额外的提示。

You may also want to read through The Java on Mac OS X About, Quit and Preferences menu items and events article, which should provide some more additional hints.

这篇关于从Java访问Mac OS X应用程序菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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