I'll try keep it short, more info at the bottom.
I am struggling to get a ListView with CheckBoxes working. I have a GUI application, and want a neat compact view so that a user can select multiple options from a list while "editing" their "profile" information without the list taking up a whole screen. So I opted for a ListView with CheckBoxListCell. I am able to initialize the list fine and checking/unchecking options triggers the wanted event, but when I scroll down the list and scroll back up the previously checked box is unchecked, and no event is triggered indicating this isn't a change event that happens when scrolling. Is this a bug or am I missing something in my initialization?
Here is the code relevant to initializing the ListView:
private void setOrgansListed(Boolean editing) {
ObservableList<OrganEnum> listedOrgs = FXCollections.observableArrayList();
if (editing) {
System.out.println("Editing");
listedOrgs.setAll(OrganEnum.values());
organsListed.setItems(listedOrgs);
organsListed.setCellFactory(CheckBoxListCell.forListView(param -> {
BooleanProperty observable = new SimpleBooleanProperty();
observable.addListener(((obs, wasSelected, isSelected) -> {
GuiUndoController.add(new Tuple<>("organ", organsListed));
}));
return observable;
}));
This is a picture of the ListView in the GUI
Extended info: I am fairly new to Java and JavaFX. I have tried using controlsFX CheckListView but there is a known bug preventing event handlers from binding after you reset the CheckListView. I need the event handler to trigger and save the state of the List so that users can undo changes. I have also found a question that is identical to this issue here, but no proper solution was provided or I am missing something.
To make sure my problem is clear: I tick "Liver" in the list, scroll to look at other items in the list, then when I scroll back up "Liver" is unchecked and no change event was triggered to indicate that the value of the CheckBox has changed.
Aucun commentaire:
Enregistrer un commentaire