Skip to content

BindableValue

Since 2.2.1

BindableValue<T> is a lightweight, invisible element that holds a single value of any type and notifies registered listeners whenever the value changes. It is useful as a non-visual reactive binding point inside a UI tree.

BindableValue extends BindableUIElement<T> and inherits the full data-binding and event system.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

java
var value = new BindableValue<String>();
value.setValue("hello", false);
value.registerValueListener(v -> System.out.println("Changed: " + v));

// Bind a text field to it
textField.bind(DataBindingBuilder.string(
    value::getValue,
    v -> value.setValue(v, true)
).build());

parent.addChild(value);

Value Binding

BindableValue extends BindableUIElement&lt;T&gt; and participates fully in the data-binding system:

java
bv.bind(DataBindingBuilder.string(
    () -> config.getName(),
    name -> config.setName(name)
).build());

See Data Bindings for full details.


Fields

NameTypeAccessDescription
valueT (nullable)private (getter)The currently held value.

Methods

MethodReturnsDescription
setValue(T, boolean)BindableUIElement&lt;T&gt;Sets the value. Second param controls notification. No-op if the value is equal to the current.
getValue()TReturns the current value.
registerValueListener(Consumer&lt;T&gt;)voidRegisters a listener called when the value changes.

Released under the MIT License.