Oracle rebooted JavaFX and finally positioned it as what I for a long time have been longing for; Swing 2.0. Let’s not kid ourselves; JavaFX is a new UI library for Java, using the API lessons learned from Swing and taking it to the next level with animations and effects. The concept is powerful enough to even go into the 3rd dimension soon. And more importantly; JavaFX2 finally has a good integration (and therefor migration path) with Swing, so it actually has an existing user base which can easily be persuaded to take a peek. Not to mention the fact that it now uses Java instead of JavaFX script, so the EDI support is great right from the start. (Well done Oracle!) But if this doesn’t sound like Swing 2.0, I don’t know what will.
So what is JavaFX2 like? Well… I like it. The API is clean and intuitive. Since it uses a different approach, making everything from simple lines to complete tables just a node in a tree, it means that I still have to really get my head around that. Fact remains that this approach allows to easily add effects and animation on anything, being it on a square or complete screen (they’re all just nodes after all). But I know I will initially use JavaFX in existing Swing applications, so my primary interest is in the controls. In order to make my life easier, I decided that porting MigLayout could be a good idea.
I must say that the initial results in my opinion are not bad at all. Below is an example of a simple test involving a TextBox and Rectangle:
public class MigPaneTest1 extends Application {
public static void main(String[] args) {
Launcher.launch(MigPane.class, args);
}
@Override
public void start(Stage stage) {
// root
MigPane lRoot = new MigPane(new LC(), new AC(), new AC());
// add nodes
lRoot.add(new TextBox(10), new CC());
lRoot.add(new Rectangle(30,30, Color.YELLOW), new CC());
// create scene
Scene scene = new Scene(lRoot, 600, 300);
// create stage
stage.setTitle("Test");
stage.setScene(scene);
stage.setVisible(true);
}
}
This results in the following layout:
(more…)