Package swingtree

Class UIForAnyToggleButton<I,B extends JToggleButton>

Type Parameters:
I - The type of this builder node.
B - The type of the JToggleButton subtype which will be managed by this builder.
Direct Known Subclasses:
UIForRadioButton, UIForToggleButton

public abstract class UIForAnyToggleButton<I,B extends JToggleButton> extends UIForAnyButton<I,B>
An abstract precursor for swing tree builder nodes for JToggleButton instances. Extend this class to create a builder node for a custom JToggleButton subtype.
  • Constructor Details

    • UIForAnyToggleButton

      public UIForAnyToggleButton()
  • Method Details

    • isSelectedIf

      public final <E> I isSelectedIf(E state, sprouts.Var<E> selection)
      Use this to dynamically bind the selection flag of the button to a Var property which will determine the selection state of the button based on the equality of the property value and the provided reference value. So if the first state argument is equal to the value of the selection property, the button will be selected, otherwise it will be deselected.
      A typical use case is to bind a button to an enum property, like so:
      
            // In your view model:
            enum Step { ONE, TWO, THREE }
            Var<Step> step = Var.of(Step.ONE);
      
            // In your view:
            UI.radioButton("Two").isSelectedIf(Step.TWO, vm.getStep());
        
      As you can see, the radio button will be selected if the enum property is equal to the supplied enum value and deselected otherwise.

      Hint: Use myProperty.fire(From.VIEW_MODEL) in your view model to send the property value to this view component.
      Type Parameters:
      E - The type of the property value.
      Parameters:
      state - The reference value which this JToggleButton should represent.
      selection - The Var instance which will be used to dynamically model the selection state of the wrapped JToggleButton type based on the equality of the state argument and the value of the property.
      Returns:
      The current builder type, to allow for further method chaining.
      Throws:
      IllegalArgumentException - if selected is null.