JavaFX 8, ListView with Checkboxes

前端 未结 3 1173
眼角桃花
眼角桃花 2021-02-20 02:52

I want to create a simple ListView. I have figured out I can use the method setCellFactory() but I don\'t understand how to use them correctly. So far I have:

         


        
3条回答
  •  一整个雨季
    2021-02-20 03:16

    Thanks for previous answers. I miss the information that setCellValueFactory is not needed, but value assigned should also be done in setCellFactory. Here is my approach (much copied from previous solution).

    public TreeTableColumn treetblcolHide;
    ...
        treetblcolHide.setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(new Callback>() {
            @Override
            public ObservableValue call(final Integer param) {
                final RowContainer rowitem = treetblcolHide.getTreeTableView().getTreeItem(param).getValue();
                BooleanProperty observable = new SimpleBooleanProperty();
                observable.addListener(new ChangeListener() {
                                           @Override
                                           public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) {
                                               rowitem.setHideMenuItem(newValue.toString());
                                           }
                                       }
                );
                observable.setValue(Boolean.parseBoolean(rowitem.getHideMenuItem()));
                return observable ;
            }
        }));
    

提交回复
热议问题