Saturday, September 15, 2012

Touch me...


again a short post about using the touch api in JavaFX to interact with a control. I played around with the touch api last week and used it to move the pointer of a gauge with my fingers. 
That was something I would like to do for months and I really was surprised how easy it was to realize.
This morning I read a comment on one of my last posts where someone created a gauge where you could drag the pointer to a certain value and I thought it might be a good idea to share this touch thing with you, so here we go...
First of all I created one of my gauges with the following code...

final Gauge radial = 

which leads to the following gauge...

By the shows the new brushed metal background that is now also available in the JFXtras gauges :)

In the next step we have to add the EventHandler for the RotateEvent...

private double value = 0;

  new EventHandler<RotateEvent>() {
    @Override public void handle(RotateEvent event) {
      value = radial.getValue();

  new EventHandler<RotateEvent>() {
    @Override public void handle(RotateEvent event) {
      radial.setValue(value + event.getTotalAngle() /

And that's all I have to do to receive rotation events from the touchpad of my Macbook Pro and use the values to rotate the pointer of my gauge...nice isn't it...

For those of you who would like to see it in action I recorded a short video with my iPad (so the quality might be not ideal) you go...

That's all I wanted to share with you so...keep coding...


  1. Very, very cool Gerrit!!! I was playing around with touch on Windows 7 recently and am just amazed how easy it is to implement stuff.

  2. Hi gerrit,
    i'm trying to do many gestures and other new events but not quiet easy at all. My computer doesn't support any of them. I've android device with 1ghz can i run javafx implicitly using rooted Operating system.


  3. Hi Narayan,
    I think it won't work on an Android device at the moment. An idea would be to buy the Apple MagicPad (not sure if they have Linux drivers but it should work on OS X and Windows) because it seems to be the same technology as the MBP trackpad (which works).