0

I'm trying to set the default selected value for a ControlsFX CheckComboBox v8.0.3 with Java 8

I have tried the accepted answer in this question, but when I try

CheckComboBox.getCheckModel().check(0);        

I get a class can not be referenced from a static context. When I try the following I get cannot resolve method check(int);

final CheckComboBox<String> checkComboBox = new CheckComboBox<>(strings);
checkComboBox.getCheckModel().check(0);  

If I try getCheckmodel().selectIndices(0) the first All1 is populated to the CheckComboBox only when a new value is selected from the CheckComboBox. Is there a way to refresh the comboxBox after selecting the indices or any other way to achieve what I want?

Text numberTypeText = new Text("Features supported:");
final ObservableList<String> strings = FXCollections.observableArrayList();
strings.add("All1");
strings.add("All2");
strings.add("All3");
strings.add("All4");
strings.add("All5");
strings.add("All6");
strings.add("All7");
strings.add("All8");

final CheckComboBox<String> checkComboBox = new CheckComboBox<>(strings);
        checkComboBox.getCheckModel().selectIndices(0);

checkComboBox.getCheckModel().getSelectedItems().addListener(new ListChangeListener<String>() {
    public void onChanged(ListChangeListener.Change<? extends String> c) {
        System.out.println(checkComboBox.getCheckModel().getSelectedItems());
    }
});

Any help would be appreciated.

1 Answers1

0

When I try the following I get cannot resolve method check(int);

It is because you are using very old version of ControlsFX. Upgrade your ControlsFX to newer version.

If I try getCheckmodel().selectIndices(0) the first All1 is populated to the CheckComboBox only when a new value is selected from the CheckComboBox.

This seems like a bug which is fixed in newer version of ControlsFX.

In v8.40.14, I was able to set the default checkboxes using check() method:

checkComboBox.getCheckModel().check(0);

Or, checkIndices() method if you want to check multiple items:

checkComboBox.getCheckModel().checkIndices(0, 1);
THe_strOX
  • 687
  • 1
  • 5
  • 16