The Artima Developer Community
Sponsored Link

Artima Developer Spotlight Forum
Amy Fowler on Using JavaFX with Swing

3 replies on 1 page. Most recent reply: Jun 19, 2009 2:46 AM by Nick Evgeniev

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Amy Fowler on Using JavaFX with Swing Posted: Jun 18, 2009 9:40 PM
Reply to this message Reply
Advertisement

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?


Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Amy Fowler on Using JavaFX with Swing Posted: Jun 19, 2009 1:21 AM
Reply to this message Reply
> 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.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Amy Fowler on Using JavaFX with Swing Posted: Jun 19, 2009 1:58 AM
Reply to this message Reply
> One step for two steps back. Give Swing yet another try on
> the web.

I haven't gotten too far into JavaFX yet, but I'm pretty sure JavaFX + Swing is limited to desktop apps not web.

Nick Evgeniev

Posts: 16
Nickname: nevgeniev
Registered: Aug, 2007

Re: Amy Fowler on Using JavaFX with Swing Posted: Jun 19, 2009 2:46 AM
Reply to this message Reply
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 :)

Flat View: This topic has 3 replies on 1 page
Topic: Pondering Actor Design Previous Topic   Next Topic Topic: JCP Launches Collaborative Site, Hosts Virtual Town Hall

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use