Tag Archives: javafx

Analog Clock Revisited

Posted on by

Screenshot of the analog clockI have been playing around with JavaFX on and off since it came out and I got really inspired by Per’s blog post about the analog clock. So I decided to spend my time at the Crisp Hack Summit trying to improve Per’s design both in code and visually.

read more »

Window, Scene and Node coordinates in JavaFX

Posted on by

Here is an illustration on how the coordinate systems of the screen and JavaFX objects relate to each other. It is a great thing with JavaFX that you seldom bother about screen coordinates. Instead you rely on layout managers to position your nodes on screen. A node has its own coordinate system, should you like to do some positioning, e.g. in a game.
read more »

An Analog Clock in JavaFX

Posted on by

JavaFX is great fun but there are so many ways of doing things. You can use FXML, you can use images to build things piecewise or you can write code for a live, scalable design.  The latter is the case here where I show how I created an analog clock using Java code.

Analog Clock with desktop in background
The clock is designed with the clockwork in a separate class and the face in another.

This text shows some example JavaFX code in Java slightly above introductory level. You should have your development set up and done at least a first program.

read more »

Some Gotchas for Java Developers Learning JavaFX

Posted on by

In an earlier post, I had attached slides from a presentation on JavaFX that contained some code examples. I discovered that at least one of them, the ball game, stopped working when I switched to JavaFX 1.3.

I would say it is a quite subtle difference.

What happened was that the onKeyPressed and onKeyReleased were not called. My immediate reaction was that it was due to some bug in JavaFX but yesterday I realized what had happened.

read more »

Jada jada JavaFX – Why I Love the Idea

Posted on by

The other day I held a three-hour workshop, an introduction to JavaFX for some colleagues. The great thing about doing it, is that it forced me to answer the question: why is it necessary to create a new language just for GUI?

I brought a screenshot from a sprint demo with me as an example of why we need to go beyond the current widget based thinking. The example was a table that presented opening hours per sales item. During the demo it became clear how hard it was to understand the concept from the GUI. It did not show through, so to speak.

Standard widgets like tables and buttons are not sufficient to represent all kinds of information. The more advanced systems we build, the more power we give our users, the better we have to be at finding new ways of constructing user interfaces.

JavaFX is a promise of possibilities but you still have to think for yourself if you want to go further than adding a drop shadow and glow effect to your menues. Challenge your creativity!

Anyway, here are the slides from the presentation. There are four parts of about a dozen slides each. There is an introduction and three independent tracks that ends with a programming exercise. In three hours, there was time for only one of the three. This time, the audience selected the ball game, probably due to that the week before, the HTML5 presentation had a ball game as example. Needless to say JavaFX kicks ass compared to an HTML canvas. 🙂

Besides the ball game exercise, there is a simple button example and an example on using Inkscape with JavaFX showing how to set the identity on objects.

The Introduction. The ball game. Inkscape Example. The Button Example.


A Lean Simulation in JavaFX

Posted on by

My collagues are talking a lot about Lean these days. I thought it would be interesting to simulate one of their examples using JavaFX.

Here is a picture:

What’s cool about this then?

First, it gave me a deeper understanding of a how queue length affects cycle time. With this simulator, you can vary the parameters to control queue size and processing time. Just pull the slides.

Secondly, I knocked up this in hours and being my second JavaFX project, I consider it very fast.

There are always advocates for languages that speak loudly about how fast they write code. Sorry, I didn’t mean to be one of those.

I used almost the same number of hours with a spreadsheet to check whether the simulation was correct.

Speaking of spreadsheets, they are great tools  for understanding data.

The first point shows how JavaFX can be the same for understanding the interaction of parameters for a dynamic flow.

So the bottom line is, nothing beats a visual model and you can knock it up with JavaFX, being quick as a brick. (Did I just say that?)

Now, go and see for yourself: http://www.crisp.se/leanmachine

Don’t let Java ruin your JavaFX

Posted on by

Me and Oscar is currently working on a small project, just to learn JavaFX.

We stumbled on some nasty crashes which we at first did not understand.

ArrayIndexOutOfBoundsException? Is there a bug in JavaFX?

It turned out to be a callback from Java. Let us see how we got there.

The application we are doing is based on Crisp’s famous planning poker cards. They are great but you need to be in the same room. So we thought, why not do an online version for those teams that are geographically disperse?


The table has room for you and 8 other players. As you see from the picture, there is also a text chat to the right. At the same time, a small bubble appears by the card of the player that wrote in the chat. The bubble fades away after a ten seconds, unless the player makes another comment within that time. In that case, the latter comment is added to the bubble and it was here our problems showed up.

The chat is using a standard protocol, XMPP, to talk to the server. We don’t have to provide our own server, any chat server that speaks XMPP will do, e.g. jabber.org. Of course, all players need to have an account there.

Here is a strength that JavaFX has as newcomer, you can use existing Java libraries.

We found Smack that talks XMPP and did a small test in Java to see that we had understood it.

Now, how do one provide a JavaFX class that receives callbacks from Java? Each time there is a message from the chat, Smack will call your PacketListener. That is an interface and JavaFX does not have interfaces. It turned out to be so straightforward, however. Just extend the PacketListener interface as if it had been a class.

Here is a code snippet:

So we override the function that gives us the packet. Now comes the crucial part, the callback is done on its own thread. JavaFX has a single thread model for everything in the GUI and that code is not thread safe.

In our case we wished to display a bubble if there was none, or add to an existing one.

You should not do that. You should wait in line for your turn. Or something nasty may happen.

Remember Swing’s invokeLater? Here we need to say FX.deferAction. But in JavaFX we can pass functions as arguments. So here goes that part of the code.

You may also note that we use the chat channel to send commands.

So if you remember the threads, it is safe to have a callback from Java to your JavaFX code.

Too Rich For My Taste

Posted on by

Steve O’Grady gör under rubriken Too Rich For My Taste: The RIA Q&A ett passionerat och välformulerat försvar av den öppna webben, dvs HTML, CSS, JavaScript, och därmed också Ajax. Han menar att Silverlight, Flex/Apollo och JavaFX är fel väg, och han tror inte heller att de kommer att lyckas med annat än bli niche-spelare. Han citerar också en massa folk med liknande åsikter. Kommentarerna är också läsvärda! Kanske det intressantaste jag läst denna månad.

Nu ska jag cykla Vätternrundan! Önska mig lycka till! Jag behöver det…