When Sun first announced its JavaFX UI language and runtime, long-time Swing developers were initially frustrated that the company decided to dedicate scarce resources to a completely new UI environment instead of improving the Swing APIs.
The complaint can be explained in part by the difficulty with which JavaFX could be used to enhance existing Swing applications. While adding JavaFX to a Swing application is still difficult, Sun's most recent JavaFX SDK has significantly improved the ability to use Swing components from within JavaFX. In a recent blog post, Insider's Guide to Blending Swing and JavaFX, noted Sun UI engineer Amy Fowler provides 10 steps in which Swing can work well in JavaFX.
Among Fowler's conclusions is that:
You can blend the strengths of Swing and JavaFX to give your Java applications that visual edge that users are coming to expect from modern clients.
Fowler's first advice is to find areas where a Swing application can truly benefit from JavaFX's strenghts, such as effects and animation without standing in the way of the user:
The nicest interfaces use effects and animation in subtle ways to bring fluidity to the UI.
In addition, one should understand the differences between Swing's mostly procedural development model versus JavaFX's declarative way of creating UIs:
I'll admit there was a little hump to get over in learning to think declaratively vs. procedurally, but once that clicked, I found I can't imagine living without the JavaFX script features of binding, function pointers, and sequences.
A JavaFX application centers around a stage, and Fowler advises that developers become comfortable using the Stage and layout classes:
Starting simply, you can look at the container classes in javafx.scene.layout (Flow, Tile, HBox, VBox, Stack, and Panel). It's amazing how far one can get by nesting HBox and VBox. If you want the more sophisticated power of a grid style layout, you can use either Stephen Chin's Grid container or MigLayout (ported by Dean Iverson) in the JFXtras library.
Embedding Swing components inside a JavaFX application can be accomplished with the SwingComponent.wrap() function:
Any Swing component can be embedded in a JavaFX scene graph using the SwingComponent wrap() function. This conveniently allows you to directly leverage those Swing components which you've already configured, customized, and hooked to your application data; all that Java code can remain happily unmodified. Once you've created the structure of your scene's layout, you can pull your Swing components into the appropriate locations.
To be sure, there are limits to the degree JavaFX code can directly manipulate Swing components embedded in this manner. To make that interaction smoother, JavaFX-specific binders can be provided for specific Swing components.
Once a Swing component is embedded in a JavaFX application, that component can be manipulated just like any other JavaFX component can, including rotating, skewing, or setting the component's translucency.
What do you think of the Swing/JavaFX integration outlined in Amy Fowler's article?
> The complaint can be explained in part by the difficulty > with which JavaFX could be used to enhance existing Swing > applications.
One step for two steps back. Give Swing yet another try on the web.
With a community like this JavaFX for RIA is just stillborn but maybe Oracle will sex up their web forms for the intranet and so it will find its destination.
What's the point behind reanimation of ten years old corp (swing)? javafx is nothing but parody on flex. So why not just use flex? with ten years of experience in swing and about 1 year of flex adoption I can say that I will never look back :)