简体   繁体   English

Java / OS X Lion:设置应用程序名称停止与JDK1.7一起使用

[英]Java/OS X Lion: Setting application name stopped working with JDK1.7

I hitherto used the following code to set the Application Name (in the top "System" menu bar) on my Apple MacBook. 迄今为止,我使用以下代码在Apple MacBook上设置应用程序名称(在顶部的“系统”菜单栏中)。 (Actually, I think I copied this from stackoverflow.) (实际上,我想我是从stackoverflow复制的。)

Basically, have a seperate AppLauncher class that uses System.setProperty() to set the application name before creating a new Runnable for the app itself. 基本上,有一个单独的AppLauncher类,该类使用System.setProperty()设置应用程序名称,然后为应用程序本身创建新的Runnable。

Worked just fine. 工作得很好。

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. 但是,由于我下载并开始使用JDK 1.7,因此该解决方案停止了工作-就像在我找到该解决方案之前一样,我在菜单中得到的是Class Name而不是App Name。 I tried googling it, but to no avail. 我尝试谷歌搜索,但无济于事。

Here is the defunct code that used to work under JDK 1.6, reduced to the relevant parts: 这是以前在JDK 1.6下工作的已失效代码,缩减为相关部分:

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

Thanks for suggestions! 感谢您的建议!

ETA: invoking with java -Dapple.laf.useScreenMenuBar=true still works. ETA:使用java -Dapple.laf.useScreenMenuBar = true调用仍然有效。 Pu8tting the property into Info.plist might work, but I haven't tried it yet. 将属性插入到Info.plist中可能会起作用,但是我还没有尝试过。

It appears that setting the property using -D solves the problem. 看来使用-D设置属性可以解决该问题。

java -Dapple.laf.useScreenMenuBar=true …

Other approaches are mentioned in this related answer . 此相关答案中提到了其他方法。

I couldn't get the Info.plist or -D approaches to work (I'm working on distributing a JRuby App, that might have something to do with it), but for me passing the -Xdock:name parameter as mentioned in this article under the section "More tinkering with the menu bar" seemed to work great. 我不能得到的Info.plist或-D接近工作(我正在分发JRuby应用程序,可能有一些用它做),但对我来说传递-Xdock:name参数作为中提到的这个 “在菜单栏上进行更多修改”部分下的文章似乎效果很好。

Example: -Xdock:name="My Application" 示例: -Xdock:name="My Application"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM