Hello and Welcome . Today I would like to blog about the TableView of Javafx 2.0 beta b_45. If you are new to the TableView then please have a look at these class files.

The java documentation of those classes are very important for you when developing the application.

Let’s start here. First the thing what I’m going to show you is about the Cell which is the intersection of any row and column. Before going to TableCell , you can go for the TableColumn which helps to take control over the TableCell with cellFactory. The TableColumn is the column of any table which defines the new column with it’s defined named. Let’s make four columns our Test. I’m running these codes with compatible to JavaFX 2.0 build 45. So it might varies on future or on previous version of javafx.

TableColumn Defination

There is nothing hard. It’s all simple Object with setMethods. The PropertyValueFactory might be new for you. We are using the propertyvalueFactory with “album”, “title” , “artist” , “rating” because these properties are going to be implemented in our Object Class (Music.java).

Music.java

In above Music you may see Album Class which is another Class which defines brief of any album. Currently I’m just making these things easier for sample.The Album class is given below.
Album.java

We ‘ll be using Music class as the Generic Class which will be used in the TableView. So to make our TableView Object friendly we need to make the TableView like this:

CellFactory

I know you guys might be eager to make your TableCell more customize so to make cell more customizable there is the setCellFactory in Table Column. This function helps to set you own cellFactory. We’ll be customizing only two column’s cell. They are Rating and Album Art. Let’s do these stuffs one by one.

1. Rating Cell Customize

In above cell factory I’m using Music Generic class for TableColumn of Callback Object.Now we are making the TableCell Object overriding updateItem function. Here we’ve used inherited setGraphic function of TableCell class for setting the Graphics of any cell. In this way you can set any graphic for cell. I’ve used ChoiceBox for setting the graphics. The ratingSample is the final variable consisting the possible rating values of any music.

2. AlbumArt Cell Customize

In above cell factory, I’ve used my own kind of graphics. I this one cell factory is similar to previous one. Here I used the images resources of my own package “/img” .

Finally you ‘ve really customized the Cell of the table now it’s time for adding those columns and rows to table.

Fancy Stuffs

To make your table more fancy Let’s do some fancy stuffs.

You can implement these things in your Application start() function like this:

Finally your output will be like this:

Fancy Music Library Table

The full source code is here : MusicLibrary Project

Ok This much for day . If you have any problem then please comment. Have a good 🙂 day.

Thanks.