V
V
vvmax012022-03-31 17:47:53
Java
vvmax01, 2022-03-31 17:47:53

How to access all content of ListView?

I have a ListView with custom rows

class CheckListCell extends ListCell<String> {
    private BorderPane container = new BorderPane();
    private Label text = new Label();
    private CheckBox check = new CheckBox();

    public CheckListCell() {
        super();
        container.setLeft(text);
        container.setRight(check);
    }

    public boolean isBoxSelected(){
        return check.isSelected();
    }

    @Override
    protected void updateItem(String s, boolean b) {
        super.updateItem(s, b);
        setText(null);
        setGraphic(null);

        if (!b && s != null){
            text.setText(s);
            setGraphic(container);
        }
    }
    
}

generated like this
ListView list;
               ObservableList<String> items = FXCollections.observableArrayList("1","2","3");
                list.getItems().setAll(items);
                list.setCellFactory(param -> new CheckListCell());

It turns out such a list
6245be60c19d6787710485.jpeg
. The task is to find the lines for which the checkbox is selected.
Is it possible somehow having a list element to get each row separately in the form of a CheckListCell object?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question