JavaFX 8, ListView with Checkboxes

前端 未结 3 1156
眼角桃花
眼角桃花 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:09

        listView.setCellFactory(CheckBoxListCell.forListView(new Callback>() {
            @Override
            public ObservableValue call(String item) {
                BooleanProperty observable = new SimpleBooleanProperty();
                observable.addListener((obs, wasSelected, isNowSelected) -> 
                    System.out.println("Check box for "+item+" changed from "+wasSelected+" to "+isNowSelected)
                );
                return observable ;
            }
        }));
    

    Thank you! This helps me to solve my problem.

提交回复
热议问题