# CheckBoxWidgetHelper

`com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper`

**Since:** 1.8.4

A checkbox widget whose checked state can be changed by the player or a script.  
Scripted changes invoke the builder's change callback through the widget's press handler.  
```js
const screen = Hud.createScreen("a screen", true);  
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
  const box = self.checkBoxBuilder()
     .pos(10, 20)
     .size(20, 20)
     .message("enabled")
     .action(JavaWrapper.methodToJava(function (btn) {
       // the action fires on a scripted change as well as a player click
       Chat.log(`now ${btn.isChecked()}`);  
     }))
     .build();  

  // setting a different state invokes the action
  box.setChecked(true);  
  Chat.log(`checked: ${box.isChecked()}`);  
}));  
Hud.openScreen(screen);  
```

Available in scripts as `Widgets.CheckBox`.

## Nested types

- [CheckBoxBuilder](CheckBoxWidgetHelper.CheckBoxBuilder.md)

## Constructors

### new CheckBoxWidgetHelper {#com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper_constructor-Checkbox-}

```js
new CheckBoxWidgetHelper(Checkbox btn)
```

Wraps a checkbox with the default helper z-index of `0`.

**Parameters:**
- `btn`: the checkbox to wrap

### new CheckBoxWidgetHelper {#com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper_constructor-Checkbox-int-}

```js
new CheckBoxWidgetHelper(Checkbox btn, int zIndex)
```

Wraps a checkbox with the supplied helper z-index.

**Parameters:**
- `btn`: the checkbox to wrap
- `zIndex`: the helper's drawing-order index

## Methods

### isChecked {#com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper_isChecked-}

```js
isChecked(): boolean
```

Returns the widget's current checked state.

**Returns:** `true` if this button is checked, `false` otherwise.

**Since:** 1.8.4

### setChecked {#com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper_setChecked-boolean-}

```js
setChecked(boolean checked): CheckBoxWidgetHelper
```

Sets the checked state by invoking the press handler if the requested state differs
from the current state. A changed state invokes the builder's change callback; an
unchanged state does nothing.

**Parameters:**
- `checked`: whether to check or uncheck this button

**Returns:** self for chaining.

**Since:** 1.8.4

### toggle {#com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper_toggle-}

```js
toggle(): CheckBoxWidgetHelper
```

Toggles the checked state through the widget's press handler, invoking its change callback.

**Returns:** self for chaining.

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.helper.screen.CheckBoxWidgetHelper_toString-}

```js
toString(): String
```

Returns `CheckBoxWidgetHelper:{"message": "%s", "checked": %b}` with the
checkbox label and checked state; the label is not JSON-escaped.

**Returns:** the formatted diagnostic string
