- Published:November 23rd, 2008
- Comments:No Comment
- Category:Pages
I’m working in Eclipse Ganymede at the moment and just couldn’t get the title for the menu bar to work correctly. Getting the menu bar in the correct place wasn’t a problem whatsoever, but instead of my application setting the application name for the context-sensitive menu bar to whatever I wanted, it instead used the package name of the application. This is majorly frustrating, especially when you exhaust everything you think may work.
I’ll go over what’s now wrong under Leopard, or what may have even been wrong beforehand. There’s two things you need to do as follows:
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MyApplication");
The first line will place the menu bar on the screen menu bar, as opposed to the application’s typical menu bar (much like windows). The second line will change the name of the application to whatever it is you want. If you’re calling this code from the same place as your GUI is being created, it won’t work. Why? I wish I knew. Perhaps the call to set the system property within the same thread fails to make a change. What needs to be done is to move your main method to another class. My original class which was to create the entire GUI is called RootGUI. It was recommended to me that a new class called RootGUILauncher and place main in there with the correct calls to the system properties. My eventual code ended up looking like this:
package org.reformsoft.macchat.gui;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class RootGUILauncher {
public static void main(String[] args) {
try {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MyApplication");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException: " + e.getMessage());
}
catch(InstantiationException e) {
System.out.println("InstantiationException: " + e.getMessage());
}
catch(IllegalAccessException e) {
System.out.println("IllegalAccessException: " + e.getMessage());
}
catch(UnsupportedLookAndFeelException e) {
System.out.println("UnsupportedLookAndFeelException: " + e.getMessage());
}
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new RootGUI();
}
});
}
}
I didn’t expect this to work at all, but much to my surprise it did. It actually contradicts a lot of what I’ve seen on the web, and it’s very rarely mentioned. Alternative solutions are mentioned in developer connection. They seem a bit more long-winded, although they’re more robust solutions.

