javafx checkboxes in tableview


Question

I am new to JavaFX, and in my desktop application, I have a checkbox column for a certain functionality. I load those check boxes to the table view in runtime with "CheckboxCell.java".

Within my controller class, I have the following code to define the particular column:

TableColumn checkFireCol = new TableColumn("Check Car");
checkFireCol.setMinWidth(80);
checkFireCol.setCellValueFactory(new PropertyValueFactory<carModel, Boolean>("checkCar "));
checkFireCol.setCellFactory(new Callback<TableColumn<carModel, Boolean>, TableCell<carModel, Boolean>>() 
{
    @Override
    public TableCell<carModel, Boolean> call(TableColumn<carModel, Boolean> tableColumn)
    {
        return new CheckboxCell(Pos.CENTER);
    }
});

I need to print a message based on whether the check box selected or not for each row item. How can I do it using the controller class, CheckboxCell class and the table model class?

1
1
10/7/2016 3:19:25 PM

You can access the table model in your controller class like this. Note that cm.getCheckCar() is also the value of the CheckboxCell.

for(CarModel cm:carModelTable.getItems()){
    System.out.println(cm.getCheckCar());
}
0
8/22/2013 7:13:15 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon