Unable to re-enable CheckBoxGroup items via setItemEnabledProvider()

I’m using a CheckBoxGroup, and I’ve got some code that looks like this:

if (someCondition) {
	cbGroup.setItemEnabledProvider(item -> !item.equals("Value1"));
} else {
    cbGroup.setItemEnabledProvider(item -> true);
}

When someCondition is true, the checkbox item that I want disabled is correctly disabled. However later when someCondition is false, and I want to enable all the items again, the item remains disabled. What am I doing wrong?

Thanks,

  • Joe

This appears to be a minor bug – if I programmatically select()/deselect() the item that I want to re-enable, then it works as I expect, i.e.

if (someCondition) {
	cbGroup.setItemEnabledProvider(item -> !item.equals("Value1"));
} else {
	cbGroup.setItemEnabledProvider(item -> true);
	cbGroup.deselect("Value1");
}

the problem here seems to be that you don’t re-run the whole if-condition code later when someCondition has changed, therefore the ItemEnabledProvider set on the group is still the same.

I believe it should work if you put the whole if block inside the ItemEnabledProvider:

cbGroup.setItemEnabledProvider(item -> {
	if(someCondition){
		return item.equals("Value1");
	} else {
		return true;
	}
}

Kaspar Scherrer:
I believe it should work if you put the whole if block inside the ItemEnabledProvider:

No, that doesn’t seem to work. When setItemEnabledProvider() is called the second time, the lambda isn’t getting called at all until the selection of one of the items changes.