3

The macify Notepad example is the only example of 'macification' I could find, and it's all fine and dandy I guess, apart from the menu which completely screws up my layout. I'm very, very new at Java so I follow examples like these to the letter, but this menu really has to go. Is there a way to catch the 'about' stuff without a menu? After all, this about thing on Mac OSes seems to be there even without one. Standard procedure, etc. I don't have a Mac to test the code, so trial and error is severely limited...

How is this done?

Erius
  • 1,021
  • 8
  • 21
  • "Macification" sadly doesn't mean much. There's hardly one OS that has been more inconsistent when it comes to UI than OS X (they recently put the buttons to manipulate windows in a **vertical** position on the latest OS X, for some apps). Unless you're looking for some kind of approval of Apple, I really wouldn't care much about it because there's not "one way" to it on OS X but tens of ways. Not to mention most apps people now use on OS X are webapps and these have their very own UI that Apple ain't choosing. Then buy a used Mac Mini to do your testing : ) – SyntaxT3rr0r Aug 31 '11 at 12:48

1 Answers1

3

Bit of a necro-post but it's code I use all the time. It's complicated and uses reflection to avoid throwing errors on non-Mac systems, however.

In the initialization of your app or as a static code block:

if (System.getProperty("os.name").contains("Mac")) {
    try {
        Object app = Class.forName("com.apple.eawt.Application")
            .getMethod("getApplication")
            .invoke(null);

        Object al = Proxy.newProxyInstance(
            Class.forName("com.apple.eawt.AboutHandler").getClassLoader(),
            new Class[]{Class.forName("com.apple.eawt.AboutHandler")},
            new AboutListener()
        );

        app.getClass()
            .getMethod("setAboutHandler", Class.forName("com.apple.eawt.AboutHandler"))
            .invoke(app, al);
    }
    catch (Exception e) {
        //fail quietly
    }
}

At the bottom of the source file after the last curly brace

public class AboutListener implements InvocationHandler {

    public Object invoke(Object proxy, Method method, Object[] args) {
        //Show About Dialog
        return null;
    }
}

When releasing a full application in java things like this make nice small touches. This should be mostly copy-and-paste-able but you will need to add a line or two to display an about box. If you need to test really badly use web-start, dropbox public links, and a neighborhood Apple Store.

iracigt
  • 282
  • 1
  • 5
  • Instead of `System.getProperty("os.name").contains("Mac")`, you should check if it contains `"OS X"` because starting with 10.8, they dropped the "Mac" from the official name, leaving just "OS X". The only reason you would still need to check for "Mac" is if you were still working with Mac OS 9 or earlier for some reason. – Thunderforge Sep 01 '13 at 20:42
  • Also, it's not really clear why you are using reflection for all of this. Why not just import `com.apple.eawt.*` and call the methods on the classes directly? That's what I do and it works just fine. – Thunderforge Sep 01 '13 at 20:44
  • The question states that a Mac was not available for testing, the use of reflection allows it to be compiled on a non-Mac system. – iracigt Sep 01 '13 at 21:23
  • Ah, I figured that you could still import the classes, just nothing would happen if you tried to use them on a non OS X system. Thanks for clarifying that. – Thunderforge Sep 01 '13 at 21:32