mardi 11 mai 2021

JavaFX CheckBoxTableCell refuses to bind to value

I have a TableView with a column that should be a checkbox for a boolean value (JavaFX 16, Java 11), but for some reason the checkbox refuses to actually bind to the field of the object. Trying to use the forTableColumn static method specifically made for boolean columns already fails, and I've tried extending CheckBoxTableColumn and making a binding inside it to no avail (though I shouldn't need to do that for just the basic binding.

In the controller of my FXML I'm calling ascColumn.setCellFactory(CheckBoxTableCell.forTableColumn(ascColumn));, with my column being

<TableColumn fx:id="ascColumn" text="Asc" prefWidth="$SHORT_CELL_WIDTH">
    <cellValueFactory>
        <PropertyValueFactory property="ascension"/>
    </cellValueFactory>
</TableColumn>

and it works of course, since the checkbox appears, but the checking and unchecking doesn't actually reach the source object. No other column needs the field to be an ObservableValue, all others can deal with it themselves, so I'm looking for a solution to doing it with the source value being just a regular boolean. I've also tried setting the selectedStateCallback to return a BooleanProperty which I then added a listener to, but the listener never gets called.

Ultimately what I want to achieve is for the checkboxes to only appear if the object of the row meets certain conditions, for which I've made a new class that extends CheckBoxTableCell, however since I can't get the default one working in the first place, I can't get that to work either, so I need to tackle this first.




Aucun commentaire:

Enregistrer un commentaire