Programmatic setting of Nifty checkboxes

Hi all,

I’ve got a nifty checkbox - i’m doing:

CheckBox cb = screen.findNiftyControl("rememberPassword", CheckBox.class); cb.check();

The checkbox returns true to isChecked - BUT graphically it does not show the check. When you click on it there is a brief glitch and then it shows checked properly.

Is there something I need to do here to cause the control to update visually after setting it programmatically?

I’m planning to use disabled checkboxes to show validity on user entry in a form later on…is that going to be a problem too?


Have you tried using:



No, there is nothing special necessary to visually update the checkbox state o_O

In the end your “cb.check()” call ends up in this method:

public void update(final boolean checked) {
final Element selectImage = getElement().findElementByName("#select");
if (checked) {
selectImage.startEffect(EffectEventId.onCustom, null, “show”);
} else {
selectImage.startEffect(EffectEventId.onCustom, null, “hide”);

The actual “checking” or “unchecking” is done using a custom effect linked to the #select element of the control. If you use a custom style you’ll need to add an effect as well but the standard case using the default controls should really update the control immediatly.

Found it!

The checkbox was hidden (the panel it was on had been created but was off screen) at the point I was setting it to checked. I was also doing a cancel of onCustom events against the root node but commenting that out didn’t fix it but I moved the checked setting until after the panel is shown and now it works.