Skip to content
Advertisement

JavaFX TableView with array of TableColumns

I got a TableView<MonthRow> where I want to display each month of the year and its relevant days.

I got those three classes for presentation purposes:

JavaScript
JavaScript
JavaScript

And then I create the table content:

JavaScript

Having the ObservableList now for the TableView, I am kinda stuck. I want to have one TableColumn for the month and 31 TableColumns for the DayCells. However, because it’s an array I am not sure how to reflect the cellData of each DayCell into each TableCell. Also, because some months do not have 31 days and therefore, the cells should not show any content for the missing days.

Each cell should show the nameOfDay() content and colouring according to the DayType (will be done in the respective cellFactory at some point).

TableView Example

This might be a completely wrong approach, so please don’t hesitate to guide me towards a different solution.

Advertisement

Answer

You can do something like this:

JavaScript

This might be a completely wrong approach

Maybe. Do you need the functionality of a TableView here? E.g. selection of a month (row), etc? Perhaps a simple GridPane inside a ScrollPane would be a more convenient approach; it really depends on your project requirements.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement