JavaFX 2.0 Developer's Guide
Steven Chin has created an excellent, thorough slide deck that illustrates with code how to develop JavaFX 2.0 applications. In the slides, there are sections for all of the controls, and how to populate them with data; how to use the various regions for layout; how to skin components to customize their appearance with CSS; developing custom controls and containers; binding; and various discussions on the internals of JavaFX.
Just as interesting are the discussions on JavaFX 2.0 development using other languages, such as Groovy, Scala, and yes, even JavaFX Script with Project Visage. This can be a very important topic for those with a significant investment in existing JavaFX Script code from their JavaFX 1.3.x work. It's also relevant since Visage continues the promise of the simplicity of JavaFX Script.
Although some people favor the newer Java APIs for JavaFX, many prefer these alternate languages as they allow you to get so much functionality out of relatively little code. Take these code snippets, for example.
Here is a simple JavaFX 2.0 application written in 19 lines of Java:
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Group root = new Group();
Scene scene = new Scene(root, 400, 250, Color.ALICEBLUE);
Text text = new Text();
text.setX(105);
text.setY(120);
text.setFont(new Font(30));
text.setText("Hello World");
root.getChildren().add(text);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Here is the same example written in 17 lines of GroovyFX:
GroovyFX.start { primaryStage -‐>
def sg = new SceneGraphBuilder()
sg.stage(
title: 'Hello World!,
show: true) {
scene(
fill: aliceblue,
width: 400,
height: 250) {
text(
x: 105,
y: 120,
text: "Hello World!"
font: "30pt")
}
}
}
And finally, the same example written in 14 lines of Visage-JavaFX Script:
Stage {
title: "Hello World!"
width: 400
height: 250
scene: Scene {
fill: BLUE
content: Text {
x: 105
y: 120
text: "Hello World!"
font: Font { size: 30pt }
}
}
}
For more information on developing the latest JavaFX 2.0 applications using various alternative languages, check out the following:
- Project Visage for JavaFX Script: http://code.google.com/p/visage/
- ScalaFX: https://code.google.com/p/scalafx/
- GroovyFX: http://groovy.codehaus.org/GroovyFX
Happy coding!
-EJB

