The impressive thing about Java FX is how well developers can use CSS to style the look and feel of the user interface.

The ComboBox component by default has an arrow icon pointing downward. The requirement given to me was to have two arrows, one pointing up and the other pointing down (see image). I figure the easiest would be to use an image to change it.

However, if the height of the ComboBox changes, so will the image. But since the image I had was small, it would not look good when it is expanded.

The solution I came up with was to change using an SVG or what is known is scaled vector graphics. This is more convenient and advantageous because even if it gets scaled to a smaller or bigger size, the quality of the graphics will still be the same.

In the CSS file, I did it like this. 

 
Now all ComboBox components in your scene, will have the up and down arrow icon.

I bet you used Java FX with Swing, hence you ended up with this problem. Sure, the tutorial leads developers into thinking that the class has to inherit Application in order to launch Java FX applications or put them in a JFXPanel container if they want to use it hand in hand with Swing.

In my case, I used Swing to open a modal Java FX window. When my code executed Platform.runLater(), that error came out.

It took me some time to figure out the solution to set up a Java FX toolkit environment in order to run Java FX applications without having to use a class that inherits Application or integrate a Stage container into the JFXPanel.

The quick solution to setting up the Java FX toolkit is to instantiate JFXPanel without even using it. Just instantiate it and then you can use Platform.runLater().

Here is a sample code.

This is how you add an inner shadow effect to either a text field or text area in Java FX.

The sample CSS code shows an upper left sided inner shadow.

Related Posts Plugin for WordPress, Blogger...