Java Swing GUIs on Mac OS X

javamacosswinguser-interface

Have you ever attempted using Swing only to end up changing courses because it just couldn't do what you wanted?

I'm pretty new to Swing, having only used it for school projects over 5 years ago, but it seems Swing has come a long way in providing a more native look and feel, so much so that I'm considering using it to develop the GUI for an app on Mac OS X. Before I do, though, I wanted to see if anyone has run into any showstopper issues that prevented them from using Swing.

Just off the top of my head, some possibilities:

  • Problems developing custom components that looked "right"
  • Bad interactions with native applications and widgets
  • Performance issues (unresponsiveness, repaint problems)
  • Inability to mimic native behaviors (like Dock interaction)

Best Solution

Swing isn't going to give you perfect fidelity with the hosting OS. Sun simply can't devote the considerable resources necessary to do so. My impression is that Swing has gotten much better, but is still going to look out of place by default.

The minimum required to even hope to pass as a Mac app:

  • package your .jar in a .app
  • set the L&F to system default
  • set apple.laf.useScreenMenuBar property to true
    • must do this before any UI code

Dock interaction is non-existent in standard Java. You'll have to use Apple's Cocoa-Java bridge, which is no longer supported. I have no idea how tractable JNI is on OS X, which is the only real alternative.

Performance shouldn't be a problem. Drag & Drop is probably as hairy on OS X as it is everywhere else.

Basically, if you're explicitly targeting OS X you're best off using Objective-C. Its far from impossible to build an app on OS X using Java & Swing, but its a lot of work to make it look "native".