Java Swing GUIs on Mac OS X - java

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:
Quaqua look and feel
MacWidgets
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:
Making Java/Swing Applications Look (More) Like
Native Mac OS X Applications
Java: How to handle drop events to the Mac OS X Dock icon

#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

Related

Query regarding Widget toolkits

I need to create a desktop application for Windows as primary OS and Linux secondary. The programming language i prefer is Java since most of the backend work is in Java. I checked Qt, Gtk+, wxWidgets but was not able to come to a conclusion as which one is better. Can you suggest as of today which widget toolkit is good with support for Java? Also its fine if its not open source.
Another important aspect is I would like to know if the toolkit would create with UI native to the OS or will it have its own theme?
Well, the two best-known ones for Java are SWT and Swing. SWT will look more native, since it uses the OS's widgets. Swing will have its own look, but you can get it to emulate the OS's look. They are both available for Windows, Mac, and Linux.
There are a few more options. One thing you could look into is Jambi, which is the Java binding for Qt. It looks pretty native on all platforms it supports, and again supports Windows, Mac, and Linux.
You could also get other toolkits to work with Java using something like JNI or JNA. Look at this question regarding what the best one to use is for your situation. I bet you could easily get GTK+ to work with JNA, since it's purely a C interface, but I haven't tried it personally.

Cross-platform desktop development

I need an advice for cross-platform engine/framework for desktop PC application development (Windows, MAC, Linux). I see 3 possibilities, Qt, Java and Adobe AIR.
It must be easy to install (run-time is a drawback, but C++ wrapper and/or installer can solve the issue I think).
It must be fast and have a rich GUI (not 3D game, but definitely some 2D graphics).
The development environment must be easy to establish and the UI development tool must have drag&drop functionality to define application layout.
Target application must have native look and feel. The professional paid support should be available.
All of these criteria are met by Qt, with the exception of "native look and feel". There is no such thing as a cross-platform framework with native feel, especially on OS X, where users are very demanding about the "feel" of applications. If you really want native look and feel, you are best served by writing a shared framework in C++ or C# and then providing native GUI on each platform (you can use MonoMac to provide a native Cocoa UI using C# instead of the native Objective-C, if that's your cup of tea).
That said, we've been very happy with Qt (and the Commercial support) for cross-platform development. Particularly the new OpenGL accelerated 2D Scene API makes animated UIs quite easy. QtCreator is a decent IDE with visual designer support.
Contrary to others, probably due to the fact that I worked on a real-time trading Swing application, I consider Java to be the best answer to your requirements (however, i consider this question as subjective, as previous answers already shows). Let me develop.
It must be easy to install (run-time is a drawback, but C++ wrapper and/or installer can solve the issue I think).
Using Java, you can rely upon Java Web Start, which is, as far as i know, the best solution for easy to use applications : you click a link on the browser, and the application is installed in start menu/desktop and started as soon as it is downloaded. Seems like Adobe AIR offers an equivalent feature, but to my mind Java Web Start integrates, due to the deepness of its ecosystem, far more powerfull distribution solutions (like, as an example, the easy ability to generate the .jnlp file on demand).
It must be fast and have a rich GUI (not 3D game, but definitely some 2D graphics).
Contrary to most popular belief, generating good graphics in Java is possible. Take as an example a look at excellent filthy rich clients companion site of the excellent book.
The development environment must be easy to establish and the UI development tool must have drag&drop functionality to define application layout.
Eclipse is a defacto industry standard for IDEs, and it integrate multiple DnD IDE builders. I would simply take as example the recently liberated Windows Builder Pro.
Target application must have native look and feel. The professional paid support should be available.
Well, Swing default look'n'feel is indeed a little different from system one. however, there are excellent third-party ones, listed here, as an example.
Finally, some examples :
the excellent Palantir Technologies blog list some outstanding Swing applications
Gephi is a rather complete and efficient high-volume graph viewer
My previous work (don't consider it as a masked ad, it's only a way to show some rather solid Swing).
I would not recommend Java for desktop development. I do not care what other say, Java is still slow compared to native languages like C++. I would go with Qt. The IDE has a GUI builder and can be integrated into Eclipse or Visual Studio.
Here's a helpful resource:
http://qt.nokia.com/products/
Have a look at Appcelerator Titanium: it basically wraps a web app in a browser. You can have anything you want in a GUI using wen tech, but it looks like an ap[p.
Strangely, nobody mentioned Real Studio (now Xojo) which does meet all your requirements:
It is easy to install and does not require a separate run-time
It compiles to native code so is reasonably fast
It has a good UI library that is native for each platform
The IDE is very nice with drag and drop UI designers
Target applications are fully native and use native controls
First of have to mention http://wxwidgets.org/ , one of the most popular X-platoform frameoworks. Depending on the complexity of your application and the requirements to the "nativeness", a cross-platform framework may work for you. The x-platform applications built with framework usually feel a bit "alien", especially on the Mac, but workable. A good example is http://taskcoach.org/.
If your users are tolerant to hearty download sizes, hefty memory requirements and a bit of non-native look-and-feel then plain Java, eclipse RCP or NetBeans platform can work for you. You may save quite a bit of development time going this route.
However I am not aware of cross-platform framework that satisfies all your requirements.
If you need to get to a production-level application, the strategy that I have seen worked best was to stay native but split the UI-dependent code into cross-platform (e.g. C++ business logic) and UI. This way, you will use native interface building tools (each platform has something good there). Depending on the complexity and "finish" requirements of your application you may actually save time going this route.
A great overview of the "Native X-Platform" process can be found in this answer by Chris Hanson.

What Swing look and feel should I use for a Java desktop application?

I am developing a Java desktop application and I use Swing to build the GUI. I realize that I can change the look of my app by setting different L&Fs.
The JRE (from SUN) provides me at least two L&Fs, one is the default Metal L&F and the other is the "System" L&F which let my app have a native look. Also I can find some really cool L&Fs on the internet.
The question is: which L&F should I use for my desktop app? Someone said the native look will be more user friendly, is that true? If I use the system L&F, should I make different versions of my user handbook (since the UI will change according to the OS)?
Unless you're trying for a completely custom look for your app, I'd recommend the System L&F. It does make your application a little easier to use by making it similar in appearance to other applications on the platform, which the user will presumably be familiar with.
I'd definitely stay away from the Metal L&F. Nothing screams "Java in the late 90's" like that ugly gray chrome. (Unless that retro look is actually what you're going for.)
If you have enough users on different systems to warrant testing the UI on those systems, it wouldn't hurt to grab the screen shots for your user manual on multiple systems either. If you're making a print copy you might want to just show the most common platform, but electronic copies could be customized for each OS you've tested for.
I guess you don't mean to find the best look and feel, you are inclined to use the system look and feel but don't want to invest more workload on documentation for all platforms.
Actually you can pick a decent look and feel, like nimbus or something else as the default skin, and allow your users to choose the "skin" in the preference settings. Thus your document can just include the screenshots for the default skin.
While you do have total flexibility -- the PLAF or pluggable-look-and-feel framework is, well, pluggable -- many developers believe that users will feel that an app is weird is awkward if it doesn't look like other apps on the their operating system. To this point, Swing has an OSX look and feel that only runs on OSX, and I think the converse is true for Windows.
While it depends on your audience, of course, Swing apps made for commercial appeal generally try to use the native look and feel.
Note: On OSX, some standard OSX things like having the Quit for your app under the apple menu (and not under the file menu, like on Windows) is ONLY available in their look and feel.
Edit: For an app to be truly cross-platform, you would have to have a separate manual for different platforms if you use the native look and feel. That might be a good reason to avoid it and choose one you like, like Metal.
If cross-platformness is important for you then I'd go with nimbus (which is quite pretty unlike metal). An app that looks native will just confuse users unless it behaves exactly like a native app.

Does Java allow you to use native UI widgets on Mac OS X?

If I write an application in java, does it use native widgets if run on Mac OS X? Or does it use "lookalike" widgets provided by the java runtime?
Thanks.
You can use SWT which uses native OS X controls on OS X but also remains multi-platform (provided that platform has the SWT library compiled for it). However, it is not as flexible or will look as nice as having direct access to the UI components themselves (an abstraction has to be made).
You could also have a look at MacWidgets which attempt to be like native OS X widgets but aren't, but work cross-platform.
(source: exploding-pixels.com)
Yes. Apple provide version of jvm, which uses native widgets.
developer.apple.com/business/macmarket/tekadence.html
Benefits of Apple’s Java
implementation include access to Aqua
user interface elements “for free”
through Swing, native preemptive
multitasking, multiprocessing support
(with no additional coding required),
and treatment of JAR files as shared
libraries. This last advance improves
the speed of execution and reduces the
RAM footprint of applications which
rely on the same archive, such as
applications within suites.
Additionally, Mac OS X plugs the Java
windowing toolkit directly into the
Mac’s native windowing toolkit, giving
Java applications and applets the
graphics performance benefits of
Quartz, one of three powerful graphics
technologies on Mac OS X.
All Java Swing components are look-alike, not native widgets.
Swing's configurability is a result of a choice not to use the native host OS's GUI controls for displaying itself. Swing "paints" its controls programmatically through the use of Java 2D APIs, rather than calling into a native user interface toolkit.
There is an OSX look and feel, provided by the Apple JVM, but it is never actually native controls. The other approach is SWT, but I honestly haven't seen many applications other than Eclipse using it, and I never really find that they look very good.

Cross-Platform Programming Language with a decent gui toolkit?

For the program idea I have, it requires that the software be written in one binary that is executeable by all major desktop platforms, meaning it needs an interpreted language or a language within a JVM. Either is fine with me, but the programming language has to balance power & simplicity (e.g. Python)
I know of wxPython but I have read that it's support on Mac OS X is fairly limited
Java sounds good & it looks good but it seems almost too difficult to program in
Any help?
I used Python with wxPython for quite a while and found it very easy to use. I now use Java with both Swing and SWT.
I prefer Java but that's just a personal preference so you shouldn't let that sway you.
I didn't find the transition from Python to Java that difficult. In terms of GUI, they both have the layout manager paradigm - the managers are different but not so different you'll have trouble switching.
Java has an absolute huge class library to the point where you probably don't need to write your own version of anything, just string together the components. I never really got that deep into Python but it may well be similar. One thing I did notice is that all the really good stuff I used in Python (e.g., s[-4:-1]) could still be done quite easily in Java. Both languages were a step up from C where I had to manage strings with my own libraries.
If you think wxPython is limited on MacOS, you should try Java. I run my Java code on Windows, Linux and other UNIXes without compatibility problems. Sadly, not Mac, so I can't really advise you there.
My advice, pick a smallish project - do it in both Python and Java - see how it runs on all the platforms you're interested in.
Python with PyQt or the eventually-to-be-equivalent-but-gratis PySide seems the way to go -- after all, few languages are easier to program in than Java (which you consider "almost too difficult to program in"), Python is one of those few, Qt arguably the best cross-platform GUI toolkit in any language, and PyQt (now, but GPL or for-$$$) or PySide (eventually, gratis even if you want to close-source your own code) are powerful interfaces between Python and Qt.
You can use any of languages targeting JVM, e.g. Jython (Python impl) and JRuby (Ruby impl).
You can try using Qt bindings for Python, Qt seems to support many of Mac OSX specifics.
Consider Tcl/Tk. I'm not sure how you define "one binary that is executeable [sic] by all major desktop platforms" but Tcl probably meets this as well as java, and likely better than any other scripting language.
Using the tcl packaging technology of starkits you can either a) create a single file that can be run on any platform that has an appropriate runtime engine (and they are available for all major and many minor platforms), or you can package that platform-specific runtime engine and and cross-platform starkit into a single file executable for each platform.
The starkit technology is something other languages should aspire to. What you get is a complete, fully functional virtual file system within a single file. This lets you easily package up sound files, dll/.so files (which must be copied to disk for obvious (?) reasons), images, data, etc along with your executable code.
Tk, the graphical library, is very mature and has really good support on all platforms. Some people think it looks dated but those impressions are usually based on information that is at least 5 years old. Modern Tk looks quite good. For some examples see the tkdocs website. I's not clear whether you're more concerned with eye candy or functionality, but if it's functionality you're interested in then Tk is something to seriously consider.
Most agree that Tcl is an aquired taste but those that use it professionally usually swear by it. I've been doing wxPython programming the last several months and would switch back to tcl/tk in a heartbeat if given the opportunity.
You could use Groovy to work around the Java complexities.
Still you'll need good foundations of Swing.
While the learning curve may be steep, the trade of of not having to completely re-write the whole application again for the next platform will be a good reward.
Bear in mind, that even though it is cross platform, you should consider different platforms still have different idioms ( e.g. Copy/Past in Windows is ctrl+v, ctrl+v while in Mac it is cmd+c, cmd+v )
I work on a program that has to run on Windows, Linux and OS X (and OS X is my development platform), and wxPython is what we use.
If I had a chance to start again, I'd probably go with PyQT (based on advice from friends), but wxPython will get the job done.
I think wxPython is pretty good, though I am not sure what you mean by "support on Mac OS X is fairly limited" but I have been porting a wxPython app (www.mockupscreens.com) to Mac and it wasn't that difficult with few tweaks e.g. some UI elements may not come up as you expected, as wxPython uses native UI elements, which can be an advanatage or disadvantage based on your requirements.
Other good option is PyQT which will give you consistent look on all platforms.
Java seems better for what you want.
Well what about the web application in Javascript?
How about SWT
Cross Platform
Native Look and feel
Huge community
Constantly maintained/upgraded ( IBM backed )
Atleast one mega successful cross platform project
I would suggest going the wxPython route, I know that wxWidgets (which is what wxPython is using) can be made to have great looking Mac apps (look at PgAdmin3 from postgresql). While PgAdmin3 is not done in python, it was done with wxWidgets and looks fine on a mac.
I use three cross-platform tools regularly: Realbasic from Realsoftware which is what Visual Basic v6 would have been if allowed to grow; Revolution from Runrev which is what Hypercard would have been if allowed to survive (and its neat using a scripting language whose syntax is basically English); and finally, Delphi Prism with Mono.
All are quite mature and yet expanding at a great rate. For instance, Revolution is just introducing a web-application feature to its language that is really easy to use.

Categories

Resources