Class ButtonBuilder<B extends ButtonBase>

java.lang.Object
com.dua3.utility.fx.controls.ButtonBuilder<B>
Type Parameters:
B - the type of Button subclass to build

public class ButtonBuilder<B extends ButtonBase> extends Object
The ButtonBuilder class is a utility class used to build Button instances in a fluent way. It provides methods to set properties such as text, graphic, tooltip, action, and disabled state of the button. The built button can be obtained by calling the build() method.

Usage example:

     
     ButtonBuilder<Button> builder = new ButtonBuilder<>(Button::new);
     Button button = builder
         .text("Click me")
         .graphic(new ImageView("icon.png"))
         .tooltip("Tooltip text")
         .action(event -> System.out.println("Button clicked"))
         .bindDisabled(disabledProperty)
         .build();
     
 
In the example above, a new ButtonBuilder instance is created and bound to the Button class. The text, graphic, tooltip, action, and disabled state of the button are set using the builder methods. Finally, the build() method is called to create the button instance with the specified properties.
  • Method Details

    • text

      public ButtonBuilder<B> text(String text)
      Set text for the button.
      Parameters:
      text - the text
      Returns:
      this ButtonBuilder instance
    • graphic

      public ButtonBuilder<B> graphic(Node graphic)
      Set graphic for the button.
      Parameters:
      graphic - the graphic to use
      Returns:
      this ButtonBuilder instance
    • tooltip

      public ButtonBuilder<B> tooltip(String tooltip)
      Set tooltip for the button.
      Parameters:
      tooltip - the tooltip text
      Returns:
      this ButtonBuilder instance
    • action

      public ButtonBuilder<B> action(EventHandler<ActionEvent> action)
      Set event handler for the button.
      Parameters:
      action - the EventHandler
      Returns:
      this ButtonBuilder instance
    • action

      public ButtonBuilder<B> action(Runnable action)
      Set action for the button.
      Parameters:
      action - the action to perform when pressed
      Returns:
      this ButtonBuilder instance
    • bindDisabled

      public ButtonBuilder<B> bindDisabled(ObservableValue<Boolean> disabled)
      Bind the button's disabled state to an ObservableValue.
      Parameters:
      disabled - the value to bind the button's disableProperty to
      Returns:
      this ButtonBuilder instance
    • build

      public B build()
      Build the button.
      Returns:
      new button instance