Swing application menu name does not display correctly in Java 1.8

Okay, that's why I used to make Swing applications, and I know if you want to display a different name for the application menu (on a Mac, which usually has the "Preferences" and "Exit" System.setProperty("com.apple.mrj.application.apple.menu.about.name", "App name"); ), you have to use: System.setProperty("com.apple.mrj.application.apple.menu.about.name", "App name"); and it must be done before creating the JFrame. I did this, but it continues to show the name of my main class as the name of the menu, as if I did not write this line of code at all. I googled for this problem, but could not find anything useful, and then I just searched here, but everyone who had a similar problem had Java 1.5, 1.6 or 1.7 working. So I thought that maybe this is due to my current version of Java 1.8.

This , this, and this do not work. This , this, and this sent me to outdated information, or the links no longer worked. In addition, I am running Mac 10.8.

Any suggestions and answers are welcome.

Update:

here is the code i originally had:

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

And apparently, I need 10 reputation to send images, so I can’t show the result, but it didn’t work.

+5
source share
1 answer

Using Java 8 on Mac OS X 10.9, Setting the System Property

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

It turns out to be ineffective when changing the name displayed in the application menu. Alternatives that still work include the following:

  • By default, the application menu displays the simple name of the class specified on the java command line or the Main-Class attribute of the JAR manifest.

      java -cp build/classes mypackage.Name java -jar dist/MyJar.jar 
  • Use the -Xdock:name="Name" command line -Xdock:name="Name" .

     java -Xdock:name="Name" -cp build/classes mypackage.Main java -Xdock:name="Name" -jar MyJar.jar 
  • Add the application JAR to the Mac application package, as shown here , add the attribute to Info.plist .

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

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


All Articles