Skip to content

CheckBoxWidgetHelper ​

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

Since1.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 ​

Constructors ​

new CheckBoxWidgetHelper ​

new CheckBoxWidgetHelper(Checkbox btn)#
Wraps a checkbox with the default helper z-index of 0.

Parameters:

  • btn: the checkbox to wrap
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 ​

isChecked(): booleanSince1.8.4#
Returns the widget's current checked state.
Returns: true if this button is checked, false otherwise.

setChecked ​

setChecked(boolean checked): CheckBoxWidgetHelperSince1.8.4#
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.

toggle ​

toggle(): CheckBoxWidgetHelperSince1.8.4#
Toggles the checked state through the widget's press handler, invoking its change callback.
Returns: self for chaining.

toString ​

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