Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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)

share|improve this question

4 Answers 4

up vote 15 down vote accepted

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.
share|improve this answer
    
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 Dec 24 '12 at 6:21
    
That "best IDEs in the world" link should really just point to IntelliJ IDEA ;) Great answer, very informative, thanks! –  Neeko Dec 24 '12 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. –  Neeko Oct 26 '13 at 17:30

I think Java Swing is faster than JavaFX.. the fact that JavaFX has built with richer UIs in it. So I really think that you should go for Swing with SwingX if you like..

About the MVC pattern in Swing.. I don't really know how to do it with creating with GUI or maybe it's just me. But I really suggest using Swing in that matter..

share|improve this answer
2  
This is completely incorrect. If you are talking about performance Swing is significantly slower than JavaFX. JavaFX is a newer technology that deals directly with the graphics drivers and host OS where as Swing does all of it's drawing in Java UI thread, which is awful. If you have a brand new application JavaFX is the way to go. –  Andrew Finnell Dec 23 '12 at 14:43
1  
I have to down vote due to how wrong this answer is. As Andrew Finnel points out, JavaFX is much faster than Swing. –  Neeko Dec 23 '12 at 14:57
    
Aah! Thanks for clearing that out. That's just based on me. Thanks :) –  Mark Vizcarra Dec 24 '12 at 1:49
    
But does JavaFX consumes much memory than Swing? –  Mark Vizcarra Dec 24 '12 at 1:50
    
@Neeko not true, event Graphics/2D is more optimalized, performance / logics is similair as by choosing Nimbus L&F –  mKorbel Jan 8 '13 at 14:34

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.

share|improve this answer

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

share|improve this answer
    
Thank you! I think I've decided to go with JavaFX, but will read about MVP and how it can be used with this platform. –  egor Dec 24 '12 at 6:44
1  
Great! If you decide to use the MVP pattern, here's a link that provides an example in JavaFX code.google.com/p/pennychecker-presenter/wiki/JavaFxMvpExample –  Neeko Dec 24 '12 at 15:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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