Kint Summons
Kint Summons

Reputation: 11

How to Tell How Many Items are Selected in a CheckComboBox?

I am using a CheckComboBox in my JavaFX project, it is part of the ControlsFX library.

Essentially what I am trying to do is see how many Items are checked and then make a certain string. For example if only 1 item is checked I want the string to say "1 Item: " and then list what that item is.If there are more than one item selected I want commas to be separating the multiple selected values. I just don't understand what methods that come with the CheckComboBox would work.

Here's some code I have now:

if (!statusBox.getCheckModel().isEmpty()) {
  if (statusBox.getCheckModel().getItemCount() == 1) {
    System.out.println("An item is picked"+statusBox.getCheckModel().getCheckedItems());
  }

So as long as the checkcombobox isn't empty, and if there is only one selected item, it will print that string. But I don't know how to count how many items are selected within the box.

Thanks!

Upvotes: 0

Views: 487

Answers (1)

Sai Dandem
Sai Dandem

Reputation: 9959

This should give you the count of the selected checkboxes.

checkComboBox.getCheckModel().getCheckedItems().size()

Upvotes: 1

Related Questions