Swing应用程序菜单名称在Java 1.8中无法正确显示 [英] Swing application menu name not displaying correctly in Java 1.8

查看:196
本文介绍了Swing应用程序菜单名称在Java 1.8中无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我之前已经完成了Swing应用程序,我知道如果你想为应用程序菜单显示一个不同的名称(通常具有首选项和退出选项的Mac上的名称),你有使用: System.setProperty(com.apple.mrj.application.apple.menu.about.name,App name); 并且必须先执行JFrame已创建。我已经完成了这个,但它继续显示我的Main类的名称作为菜单名称,就好像我根本没有编写那行代码。我搜索了这个问题,但找不到任何有用的东西,然后我就在这里搜索,但是每个遇到类似问题的人都在运行Java 1.5,1.6或1.7。所以我想也许它与我目前的Java版本1.8有关。

Okay, so I've done Swing applications before, and I know if you want to display a different name for the application menu (the one on Macs that usually have a "Preferences" and "Quit" option), you have to use: System.setProperty("com.apple.mrj.application.apple.menu.about.name", "App name"); and it must be executed before the JFrame is created. I've done this, but it continues to show my Main class' name as the menu name, as if I didn't write that line of code at all. I googled for this issue, but couldn't find anything useful, and then I just searched on here, but everyone who had a similar issue was running Java 1.5, 1.6, or 1.7. So I thought maybe it had something to do with my current Java version, 1.8.

这个这个无效。 this 这个要么发送给我过时的信息,要么链接不再起作用。此外,我正在运行Mac 10.8。

This, this, and this did not work. This, this, and this either sent me to outdated info, or the links didn't work anymore. Also, I'm running Mac 10.8.

任何建议/答案都将不胜感激。

Any suggestions/answers would be greatly appreciated.

更新:

这是我原来的代码:

package bouncing_off_axes;

/**
 * This is the driver class of this program.
 * 
 * @author Mason 
 *
 */

public class Main {

    /**
     * The driving method.
     * 
     * @param args
     */

    public static void main(String[] args) {

        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Physics Engine Practice - Bouncing Balls");
        SimulationController view = new SimulationController("Test");

    }

}

这里是垃圾邮件提供给其他人的解决方案:

And here is a solution that trashgod provided to someone else:

package bouncing_off_axes;

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;

    /** @see https://stackoverflow.com/questions/8955638 */
    public class NewMain {

        public static void main(String[] args) {
            System.setProperty("apple.laf.useScreenMenuBar", "true");
            System.setProperty(
                "com.apple.mrj.application.apple.menu.about.name", "Name");
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {

                    JFrame frame = new JFrame("Gabby");
                    final JPanel dm = new JPanel() {

                        @Override
                        public Dimension getPreferredSize() {
                            return new Dimension(320, 240);
                        }
                    };
                    dm.setBorder(BorderFactory.createLineBorder(Color.blue, 10));

                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(dm);
                    frame.pack();
                    frame.setLocationByPlatform(true);

                    JMenuBar menuBar = new JMenuBar();
                    JMenu fileMenu = new JMenu("File");
                    menuBar.add(fileMenu);
                    frame.setJMenuBar(menuBar);
                    frame.setVisible(true);
                }
            });
        }
    }

显然我需要10点声望才能发布图片,所以我无法向您展示结果,但它没有成功。

And apparently I need 10 reputation to post images, so I can't show you the result, but it didn't work out.

推荐答案

在Mac OS X 10.9上使用Java 8 ,设置系统属性

Using Java 8 on Mac OS X 10.9, setting the System property

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

似乎无法更改应用程序菜单中显示的名称。仍然有效的替代方案包括:

appears to be ineffectual in changing the name displayed in the application menu. Alternatives that still work include these:


  • 默认情况下,应用程序菜单将显示<中指定的类的简单名称code> java 命令行或JAR清单的 Main-Class 属性。

  • By default, the application menu will display the simple name of the class specified in the java command line or the Main-Class attribute of the JAR's manifest.

 java -cp build/classes mypackage.Name
 java -jar dist/MyJar.jar


  • 使用 -Xdock:name =Name命令行参数。

    java -Xdock:name="Name" -cp build/classes mypackage.Main
    java -Xdock:name="Name" -jar MyJar.jar
    


  • 将应用程序JAR添加到Mac应用程序包中,如图所示 ,将属性添加到 Info.plist

    <key>JVMOptions</key>
    <string>-Xdock:name=Name</string>
    


  • 这篇关于Swing应用程序菜单名称在Java 1.8中无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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