简体   繁体   中英

Java Swing GUIs on Mac OS X

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)

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".

As Kevin and John said you should try Objective-C, Cocoa and XCode if you are only targeting Mac users. The developer tools for Mac is freely available.

If you want to (or have to) use Java and Swing you can use some libraries to create a GUI that looks well on Macs:

For deploying your application you should read the JarBundler docs.

However, in this case interaction with dock and native applications is very limited.

Some other good links are:

@Kevin++

Using Cocoa is probably better

  • If you want it to look exactly like native applications
  • If you are targeting only the Mac

If you intend to distribute your applications for Windows, Linux, etc. Swing is a decent choice. It's better but like in any toolkit there are still issues. You'll never get a truly native look and feel with it, same goes for similar UI toolkits which claim to be "cross-platform".

The Apple Guidelines for Java development can be found here .

Swing is a nice way to go, or you can go SWT, or BOTH!

But either way, use them on top of the RCP platform. (either with Eclipse or Netbeans).

Have a look at this: http://www.adam-bien.com/roller/abien/entry/eclipse_rcp_vs_netbeans_rcp

marco

Macify可以提供帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM