编程语言
首页 > 编程语言> > 在NetBeans 7.4中为Java程序设置动态Apple菜单标题

在NetBeans 7.4中为Java程序设置动态Apple菜单标题

作者:互联网

我继承了Eclipse中构建的Java应用程序(我相信),我正在使用NetBeans 7.4进行修改.我想设置主菜单标题,它显示在Apple菜单旁边的Mac上.现在名称是MainForm,但我希望它动态更改为特定文本文件(name.txt)的内容.我查了很多关于project.properties,ANT脚本等的信息,但我找不到一种确定的(希望是跨平台的)方式来设置这个主菜单标题.我的代码中有一个函数返回这个名字,所以我可以使用它,如果有一个地方可以做到这一点.提前致谢!

解决方法:

我发现,为了在Mac OS X应用程序菜单中设置应用程序名称,并避免将其显示为Java项目的名称,您必须在应用程序周期的早期使用System.setProperty(“ apple.awt.application.name“,”你的应用名称“);

以下是我在启动应用程序的“main”java方法中设置的方法:

public static void main(String[] args)  {
    // the application menu for Mac OS X must be set very early in the cycle
    String opSysName = System.getProperty("os.name").toLowerCase();
    if (opSysName.contains("mac")) {
        // to set the name of the app in the Mac App menu:
        System.setProperty("apple.awt.application.name", "Your App Name");
        //to show the menu bar at the top of the screen:
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        // to show a more mac-like file dialog box
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        //underlying laf:
        javax.swing.UIManager.getInstalledLookAndFeels();

        // other set-up code goes here
    }
    else {  // not on Mac OS X
        // set-up code for non-Mac systems
    }

    java.awt.EventQueue.invokeLater(() -> {
        // run the program

    });

}

标签:java,macos,netbeans-7
来源: https://codeday.me/bug/20190624/1279501.html