There is no component that does this within the API of Java FX and Google searches gave me nothing so instead, I created my own.

The concept is the same with tables where rows are grouped and row headers give you the option to expand and collapse them.

For List View, I had to make my own CellFactory in order to make this work. I was surprised that I was able to make one. If this was Swing, it might have been different.

This is how my component looks like.

 

I created an entity class that contains the title and description. Let us call the class, Note. The class has an extra boolean parameter which I use told hold the state of the title if it is expanded or not. 

 
And this is how I configured my List View

 
For each entry in the list, I used a vertical box to display the contents. When the title is clicked to expand the description, the VBox will add a child so that it will be shown. If it is collapse, it will be removed.

Simple, right? Cell factories are very handy and flexible in such a way that you can render what you want displayed to the user any way you want to.

If you noticed, there is a method called createArrowPath(). That is a convenience method I made to return an SVGPath object to be used as the arrow icon beside the title header. It takes a parameter height which should be the height of the List View

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.

Java FX is Sun Microsystem’s competing version to create Rich Internet Applications (RIA) rivalling Microsoft’s Silverlight and even Adobe’s Flex. I actually checked this out before I studied Adobe Flex and I sort of did not have a clear understanding on how to go about using Java FX since I don’t use an IDE to do coding. Because I did use an IDE when I studied Adobe Flex, I was able to grasp right away how make great use with these technologies. At least with the time I spent with Adobe Flex, I don’t have to start over with Java FX dealing with the basics. I can just go straight to programming.

You are not restricted to creating RIAs for browsers and/or desktops. Java FX also supports mobile devices with its Java FX Mobile technology. Since Java FX is built on the Java platform, it leverages the features and power that the Java platform provides. The same Java FX Application that runs in the browser can run in the desktop with no coding changes needed. They’re even planning a Java FX TV, for running Java FX Applications in the TV platform (by 2010). I’ll be posting source codes about any Java FX related application I’ll be doing for test studies. Oh and this time, I’ll also be using another IDE, NetBeans.

Related Posts Plugin for WordPress, Blogger...