CheckListView multiple issues

Issue #553 new
Itachi
created an issue

I have encountered with multiple issues while using CheckListView. Particularly, using the getCheckModel() of the control.

Some problems that I have encountered :

  • Every time a new Item is added, the old item loses the check on it.
  • If the list added to the control is a sorted list, the check() fails to work.
  • Every time I make a call to getCheckModel().check(), the listener on getCheckModel().getCheckedItems() is called twice.

Here is a complete, small test application which reproduces the issue.

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.controlsfx.control.CheckListView;

public class Main extends Application {

    private int counter = 1;

    public static void main(String[] args) {
        launch(args);
}

    @Override
    public void start(Stage primaryStage) throws Exception {
        final ObservableList<Integer> listOfItems = FXCollections.observableArrayList();
        for (; counter <= 10; counter++) {
            listOfItems.add(counter);
        }
        final CheckListView<Integer> checkListView = new CheckListView<>(listOfItems);

        // Select the checkListView element just added
        // Called once, on addition
        checkListView.getItems().addListener(new ListChangeListener<Integer>() {
            @Override
            public void onChanged(Change<? extends Integer> c) {
                c.next();
                if (c.wasAdded()) {
                    checkListView.getCheckModel().check(c.getAddedSubList().get(0));
                }
            }
        });

        // On Check / Uncheck event
        // Called Twice on every check event that takes place because of the above listener
        checkListView.getCheckModel().getCheckedItems().addListener(new ListChangeListener<Integer>() {
            @Override
            public void onChanged(ListChangeListener.Change<? extends Integer> c) {
                c.next();
                if(c.wasAdded()) {
                    System.out.println("Item Checked : " + c.getAddedSubList().get(0));
                } else if (c.wasRemoved()) {
                    System.out.println("Item Unchecked : " + c.getRemoved().get(0));
                }
            }
        });

        Button button = new Button("Add");

        // Every time a new Item is added, the old item loses its check
        button.setOnAction(e -> {
            checkListView.getItems().add(counter++);

            // Remove the comments on the following piece of code, results in failure of checks on Items
            //FXCollections.sort(checkListView.getItems());
            checkListView.requestFocus();
        });
        Scene scene = new Scene(new VBox(checkListView, button), 300, 350);
        primaryStage.setTitle("Welcome");
        primaryStage.setScene(scene);
        primaryStage.show();

    }
}

If you use this example, you can reproduce first and last issue. To reproduce the second issue just remove the comment from FXCollections.sort(checkListView.getItems()); and run it again.

The last issue seems to be related to https://bitbucket.org/controlsfx/controlsfx/issue/362/checklistview-check-and-checkall-call

All the code is tested with v 8.40.9

Comments (3)

  1. Sebastian Struckmann

    I can also observe the first issue in my application. Everytime a new item is added to the CheckListView, all CheckBoxes get unchecked. Is there a plan to fix this or does someone have a workaround?

  2. Tom Campion

    I think I'm having problems with the control related to the check mark as well. I'm trying to add about 1000 items to "CheckListView" and would like the box initial state to be checked. When my list is larger than about 100 items it seems to take a very long time. It eventually does what I want but application appears hung.

    I'm adding my items then calling targetDevicesList.getCheckModel().checkAll();

    Ideally I would like to be able specify check all or none prior to loading the list.

  3. Chakshu Gupta

    I am facing the same problem. .getCheckModel().checkAll() and .getCheckModel().clearChecks() is taking too long to execute. The Application appears hung prior to completing the action.

  4. Log in to comment