So after having used xtend for a while as a pure templating language I thought it’s time to explore how it can be used when programming JavaFX.
JavaFX 2.x API is already designed to be used for lambda expression support which will come with Java 8 so e.g. all event handlers accept a SAM type as their sole parameter. xtend already provides lambda expressions and so one can write less code.
Java:
b.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent arg0) {
// Some expression goes here
}
});
xtend:
b.setOnAction [ // Some expression goes here ] // or if you have an equal-sign fetishb.onAction = [ // Some expression goes here ]
The same is true for bean properties which look like this:
Java:
Button b = new Button();
b.setText("Say hello");
String v = b.getText();
xtend:
val b = new Button(); b.text = "Say hello" val v = b.text;
The complete source code looks like this:

I’ve recorded a small video showing how to create a JavaFX project which uses xtend to the final exported application. The video highlights the amazing new feature the itemis guys added to their latest milestones when running your xtend code in debug mode – good job.
I’ll try to explore more xtend features like using the builder support but I need to first understand how this really works (too bad I missed their EclipseCon tutorial)

April 11, 2012 


Trackbacks/Pingbacks
[...] Schindl has two blog posts up regarding JavaFX and Eclipse xtend being a perfect match, and a sensationally perfect [...]
[...] Schindl has two blog posts up regarding JavaFX and Eclipse xtend being a perfect match, and a sensationally perfect [...]
[...] 29, 2012 by Tom Schindl 0 Comments So I’ve already blogged (here and here) about the prefect match between JavaFX and [...]