Set the dynamic Apple menu name for Java program in NetBeans 7.4

I have inherited a Java application built (I believe) in Eclipse, which I am modifying with NetBeans 7.4. I want to set the title of the main menu that appears on the Mac next to the Apple menu. This is the name now MainForm, but I want it to dynamically change to the contents of a specific text file ( name.txt). I was looking for tons of information about project.properties, ANT scripts, etc., but I can't find the final (and hopefully cross-platform) way to set this name for the main menu. I have a function in my code that returns this name, so I can use this if there is room for this. Thanks in advance!

+4
source share
1 answer

I found that in order to set the App Name in the Mac OS X application menu and not show it as the name of your Java project, you must set it VERY early in the application loop using System.setProperty("apple.awt.application.name", "Your App Name");

This is how I have my set in my "main" java method that launches the application:

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

    });

}
+4
source

Source: https://habr.com/ru/post/1533117/


All Articles