Java/OS X Lion:设置应用程序名称停止与JDK1.7一起使用 [英] Java/OS X Lion: Setting application name stopped working with JDK1.7

查看:118
本文介绍了Java/OS X Lion:设置应用程序名称停止与JDK1.7一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我使用以下代码在Apple MacBook上设置应用程序名称(在顶部的系统"菜单栏中). (实际上,我想我是从stackoverflow复制的.)

I hitherto used the following code to set the Application Name (in the top "System" menu bar) on my Apple MacBook. (Actually, I think I copied this from stackoverflow.)

基本上,有一个单独的AppLauncher类,该类使用System.setProperty()设置应用程序名称,然后为应用程序本身创建新的Runnable.

Basically, have a seperate AppLauncher class that uses System.setProperty() to set the application name before creating a new Runnable for the app itself.

工作正常.

但是,由于我下载并开始使用JDK 1.7,所以该解决方案停止了工作-就像在我找到该解决方案之前一样,我在菜单中得到了类名而不是应用程序名.我尝试使用Google搜索,但无济于事.

However, since I downloaded and started using JDK 1.7, the solution stopped working - I'm getting the Class Name instead of the App Name in the menu, just like before I found that solution. I tried googling it, but to no avail.

这是以前在JDK 1.6下工作的已失效的代码,简化为相关部分:

Here is the defunct code that used to work under JDK 1.6, reduced to the relevant parts:

public class AppLauncher {
public static void main(String[] args) {

    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name",
                "My Application");
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new MainWindow();
        }
    });
}
}

感谢您的建议!

ETA:使用java -Dapple.laf.useScreenMenuBar = true调用仍然有效.将属性插入到Info.plist中可能会起作用,但是我还没有尝试过.

ETA: invoking with java -Dapple.laf.useScreenMenuBar=true still works. Pu8tting the property into Info.plist might work, but I haven't tried it yet.

推荐答案

看来,使用-D设置属性可以解决此问题.

It appears that setting the property using -D solves the problem.

java -Dapple.laf.useScreenMenuBar=true …

相关的答案中提到了其他方法.

Other approaches are mentioned in this related answer.

这篇关于Java/OS X Lion:设置应用程序名称停止与JDK1.7一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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