Module com.dua3.utility.fx.controls
Package com.dua3.utility.fx.controls
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
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 Summary
Modifier and TypeMethodDescriptionSet action for the button.action(EventHandler<ActionEvent> action) Set event handler for the button.bindDisabled(ObservableValue<Boolean> disabled) Bind the button's disabled state to anObservableValue.build()Build the button.Set graphic for the button.Set text for the button.Set tooltip for the button.
-
Method Details
-
text
Set text for the button.- Parameters:
text- the text- Returns:
- this ButtonBuilder instance
-
graphic
Set graphic for the button.- Parameters:
graphic- the graphic to use- Returns:
- this ButtonBuilder instance
-
tooltip
Set tooltip for the button.- Parameters:
tooltip- the tooltip text- Returns:
- this ButtonBuilder instance
-
action
Set event handler for the button.- Parameters:
action- theEventHandler- Returns:
- this ButtonBuilder instance
-
action
Set action for the button.- Parameters:
action- the action to perform when pressed- Returns:
- this ButtonBuilder instance
-
bindDisabled
Bind the button's disabled state to anObservableValue.- Parameters:
disabled- the value to bind the button's disableProperty to- Returns:
- this ButtonBuilder instance
-
build
Build the button.- Returns:
- new button instance
-