How To Create Clickable ImageView Or Image Button In Java FX 2

In Swing, an image button is possible by setting the background color of the JButton to transparent and the image will still show its pressed and normal state effect when clicked.

In Java FX 2 however, when you add an image to the Button control and set the background to transparent using -fx-background-color: transparent, you are left with a static image that does not move whenever you click on it.

There is no ready made class in Java FX 2 that does this so the only solution left is to make one. What I did is extend from Button class and simulate the pressed and released effect by changing the padding values whenever a mouse event occurs.

That’s it! It is as simple as that.

Related Posts Plugin for WordPress, Blogger...

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *