adam bien's blog

The Relation Between Java FX (Script) And Swing - Are You Still Concerned? 📎

The concerns about the future of Swing and it's relation to Java FX seem to be all over the place right now. However - if you look under the hood of Java FX Script - all the widgets seem to wrap / need Swing components less or more directly. Java FX Script seems to use Swing components as "Service Provider".

Some Java FX samples (the declaration inside << >> refers to Java classes):

//Java FX Button

public class Button extends Widget, RotatableWidget, ActionWidget {
    private attribute button: <<net.java.javafx.ui.XButton>>;

//Java  FX Dialog

public class Dialog extends AbstractFrame {
    private attribute jdialog:<<javax.swing.JDialog>>;

//Java FX Script Frame

public class Frame extends AbstractFrame {
       
    private attribute winListener: <<java.awt.event.WindowListener>>;
    private attribute compListener: <<java.awt.event.ComponentListener>>;
    private attribute frame: <<javax.swing.JFrame>>;

[I copied the samples from Netbeans 6.0 Java FX Plugin]

The relation between Java FX Script and Swing is similar to the relation between Swing and AWT or JFace and SWT. Java FX Script is a decorator of Swing components.

However Java FX Script allows the usage of Swing components in declarative way (without the setter - style) - and is able to simplify so the Swing development. From my perspective Java FX Script can be considered as a Domain Specific Language which compiles to Java 2D / Swing. With Java FX Script the development of Swing components becomes more fluent and object oriented - so it is a nice complement and not a substitution. It is much easier to pimp up Swing apps with Java FX with some visual effects.

I'm actually less concerned with the future of Swing - during the JavaONE 2008 technical sessions enough exciting, Swing related stuff was presented (JWebPane, Scene Graph, Java 6 update 10, Applets / WebStart etc.). ...and all cool IDEs like IntelliJ / Netbeans are Swing-based :-).