11

I need to write a cross-platform GUI application to process (in multiple threads) and visualize fairly large quantities of data. Ideally the application should be relatively fast and look good.

The app's interface will consist of a table widget, a tree widget, and a custom figure-drawing widget. The user will be able to modify the data from any one of these widgets and the changes should be immediately reflected in the other widgets.

Naturally, I am planning to use MVC. However, I normally do all my GUI programming in C++/Qt, and have very limited exposure to Java. So I would really appreciate any advice on how to organize such an app in Java. In particular, should I use Swing or JavaFX? Which widgets would you pick for the job? Could you recommend any books/online tutorials that cover these aspects of the Java platform?

I will greatly appreciate any feedback. Thanks!

(this question was originally posted on Stack Overflow, but this site was suggested as a more appropriate place to ask it)

3 Answers 3

23

This is all very subjective as multiple different technologies will be able to serve your needs.

Like others, I'll probably just recommend the technology I'd personally prefer for such a project, which would be JavaFX.

Reasons I would recommend JavaFX are:

OK, I guess the above is a bit of a tangent, but I like to promote JavaFX ;-)

Anyway, to address the specific points in your question:

  • JavaFX is a cross-platform GUI framework (currently Mac/Windows/Linux).
  • JavaFX has inbuilt, high quality multiple threading support (the core framework itself is single-threaded as is just about every other GUI platform out there, but you can define your own tasks to be executed concurrently off the GUI thread so that the GUI thread remains responsive).
  • A well written JavaFX program should have no issues performing well enough to visualize fairly large quantities of data. Here is a sample JavaFX project which does that.
  • The ability to style the application via css, make use of visual effects and animation, allows you to work with designers to make your app look great or do it yourself if you have the skills.
  • JavaFX has a TableView and a TreeView you can use. There is also a combined TreeTable control which has been developed in preparation for the Java 8 release.
  • The custom figure drawing widget could use scene graph shapes or a direct draw canvas - it's really just a matter of coding style and preference.
  • JavaFX's properties and binding facilities coupled with it's event listener frameworks makes it trivial to modify data using one control and have the changes immediately reflected in other controls.
  • For MVC style development, you can write your model using plain java objects, define your view using the FXML markup language (created using the SceneBuilder graphical layout tool if desired) and define your control logic in Java (or another scripting language if you prefer), plus you should separate your style from your logic by using CSS.
  • As you have limited exposure to Java, the learning curve will be significant. There are excellent Java tutorials in addition to the JavaFX tutorials I linked to earlier which can help with this. JavaFX core code uses only facilities available in the JDK, so to use JavaFX you don't need to learn a lot of additional libraries and frameworks (as you would if you were learning JavaEE for instance). So those two tuotorial sites provide most information you need to get up to speed.
  • For app organization, if you have a complex application and need the backing of a complete, proven client application framework and don't mind doing a lot of extra learning, then you can embed JavaFX in the Eclipse RCP or NetBeans RCP, which, according to their pages could save you years of development time. I'd only advise looking at such platforms if your needs justify it though, because for small to medium size projects, it will probably be simpler to code the stuff up directly in JavaFX without the complex client platform frameworks such as Eclipse and NetBeans.
  • As to whether you should use Swing or JavaFX, I'm not really the most objective person to answer that. JavaFX definitely has shortcomings which would become apparent to you as you start to use it (as does Swing).
  • For online tutorials, I've linked to most relevant ones. There is a nice tutorial set for a complete app.
  • The books Pro JavaFX 2 and JavaFX 2.0 Introduction by Example are highly rated.
4
  • Thank you for this amazing answer! JavaFX sure sounds like a sweet platform and I am definitely going to invest a lot of time into it. Plus both books you've recommended are available at my library :)
    – egor
    Commented Dec 24, 2012 at 6:21
  • 1
    That "best IDEs in the world" link should really just point to IntelliJ IDEA ;) Great answer, very informative, thanks! Commented Dec 24, 2012 at 15:22
  • 1
    It should be noted that JavaFX currently doesn't have any accessibility support. That can be a deal breaker for some (it was for me) and will have to continue to use Swing. Commented Oct 26, 2013 at 17:30
  • JavaFX now provides accessibility support. This functionality was delivered in Java 8u40, for which JEP 204: JavaFX Accessibility was implemented.
    – jewelsea
    Commented Apr 15, 2015 at 19:12
5

Go with a Model-view-presenter pattern instead. You can view a good MVP example in Swing here via the mvp4j project.

While not Swing, I'd also check out the MVP articles over at the GWT Google Developers site for further insight on this pattern and how to apply it in Java; the same design principals stand regardless of the framework and GWT is very similar to Swing.

A quick breakdown of how MVP works:

  • View: A class that strictly contains your GUI components. No awareness of logic or model, not even event handlers. This makes views very dumb, yet very disposable and changeable.
  • Presenter: A class that handles your application logic. A presenter will bind to one (or more) view classes and handle all the necessary application logic and model control.
  • Model: Your data model objects. It's best to keep these as POJO-like as possible (plain old java objects).

When implemented correctly, MVP will make your application very decoupled and allow you to make modifications without disturbing other areas of your application.

Edit: Based on your decision to use JavaFX, I'd recommend checking out the following articles

2
2

The widgets that you require can be found in both Swing or SWT. The documentation contains examples of components (Swing) or widgets (SWT) so it will be fairly easy to identify them.

Swing is GUI library included in JDK and built from scratch. SWT is an external one and the components are based on native ones.

As for MVC, they both have support for it. In Swing you have a Model for each component that practically provides the underlying data. The component itself is both the View and the Controller.

Not the answer you're looking for? Browse other questions tagged or ask your own question.