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.

Arbitrary Update

by Kieran

I’ve had a few people wonder why I haven’t updated my blog in so long, but to be honest with you, nothing interesting enough happens to blog about, and the stuff I do want to blog about would take quite some time.

I’m currently working on a client-side application written in Java and am currently implementing the MVC side of things which is taking more time than I’d like.  I’m also working as an events organiser for a charity at the moment where we’re hoping to raise a considerable sum of money to help a load of kids around the world.  At work I’m re-designing our web interface for our ever-important Intranet applications for easier-on-the-eyes usability and compliance.  I hear horror stories of what typical web applications for other companies around the island are like so I’m putting my degree to good use which is fantastic as it’s really quite gripping, yet tedious and time-consuming work as the idea will require no more support for older browsers.  I’ve also recently sorted out my blog so I won’t receive stupidly large quantities of spam, although the spam track backs are still ever-flowing.

That’s about the height of the excitement.  Gripping, I know.