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, 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.
An 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 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);
}
});
}
}
And apparently I need 10 reputation to post images, so I can't show you the result, but it didn't work out.
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:
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
Use the -Xdock:name="Name"
command line parameter.
java -Xdock:name="Name" -cp build/classes mypackage.Main
java -Xdock:name="Name" -jar MyJar.jar
Add the application JAR to a Mac application bundle, as shown here, an add the attribute to the Info.plist
.
<key>JVMOptions</key>
<string>-Xdock:name=Name</string>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With