在Mac上设置Java Swing应用程序名称 [英] Setting Java Swing application name on Mac

查看:104
本文介绍了在Mac上设置Java Swing应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java 1.6为Mac编写Java Swing应用程序.我阅读了许多教程,它们逐步引导您如何更好地将Java应用程序与OS X集成在一起,但是有一件事我没能开始工作.我无法显示应用程序名称(Mac菜单栏中的第一个粗体菜单项).默认情况下,显示主类的全限定类名,但我无法更改它.

I'm writing a Java Swing application for the Mac using Java 1.6. I've read a number of tutorials that step you through how to better integrate your Java application with OS X, but there's one thing I haven't been able to get working. I can't get the application name (the first, bolded menu item in the Mac menu bar) to display. By default, the fully-qualified class name of the main class is shown and I can't get it to change.

此网站表示您拥有设置以下属性:

This site says that you have to set the following property:

System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");

但是那不起作用(我正在运行10.6,所以也许属性名称已更改?).

But that doesn't work (I'm running 10.6, so maybe the property name changed?).

当我在XCode中创建一个新的Java项目时(通常使用Eclipse),该名称以某种方式神奇地被设置了! (它从一个可运行的样板应用程序开始),我已经在XCode项目的各处进行了查找,以了解如何完成此操作,但是我无法弄清楚!

When I create a new Java project in XCode (I normally use Eclipse), the name somehow magically gets set! (it starts you out with a runnable, boiler-plate application) I've looked all around the XCode project for how this is done, but I can't figure it out!

我的猜测是,仅当您将Java应用程序包装在Mac * .app程序包中时,它才设置应用程序名称,但是想知道是否有人知道答案.谢谢.

My guess is that it only sets the application name if you wrap your Java application up in a Mac *.app package, but was wondering if anyone knew the answer. Thanks.

编辑:有趣的是,如果我将应用程序打包在可运行的JAR文件中,它将设置应用程序名称,但是如果我从Eclipse运行,则不会设置该应用程序名称.

EDIT: Interestingly, it sets the application name if I package my application in a runnable JAR file, but not if I run it from Eclipse.

推荐答案

在构建GUI之前,应在应用初始化期间执行以下操作:

You should do the following during app initialization, before GUI is built:

// take the menu bar off the jframe
System.setProperty("apple.laf.useScreenMenuBar", "true");

// set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");

// set the look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

更新. 上面的代码在Java 1.5中有效,但在1.6中可能无效

UPDATE. Above code works in Java 1.5, this code may not work in 1.6

对于新的Java,请参见文档:

For new java see documentation:

  1. 要么使用-Xdock:name命令行属性:-Xdock:name=YourAppName
  2. 或在信息属性列表文件(plist)中设置CFBundleName
  1. Either use -Xdock:name command-line property: -Xdock:name=YourAppName
  2. Or set CFBundleName in information property list file (plist)

这篇关于在Mac上设置Java Swing应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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