Class AlertBuilder

java.lang.Object
io.github.sosuisen.jfxbuilder.controls.AlertBuilder

public class AlertBuilder extends Object
The AlertBuilder class constructs instances of the Alert class and offers a fluent interface for creating and configuring it.

This class includes a static create method that accepts the same arguments as the original Alert constructor and returns an instance of the AlertBuilder.

You can use method chaining to call the builder methods for configuring the Alert. Finally, invoke the build method to generate an instance of the Alert class.

Note that intermediate builder methods are not evaluated until the build method is called, meaning they are evaluated lazily.

Author:
Hidekazu Kubota <hidekazu.kubota@gmail.com>
  • Method Details

    • create

      public static AlertBuilder create(Alert.AlertType alertType)
      Accepts the constructor arguments of Alert(Alert.AlertType) and returns an instance of AlertBuilder.
      Returns:
      an instance of the AlertBuilder.
    • create

      public static AlertBuilder create(Alert.AlertType alertType, String contentText, ButtonType... buttons)
      Accepts the constructor arguments of Alert(Alert.AlertType, String, ButtonType...) and returns an instance of AlertBuilder.
      Returns:
      an instance of the AlertBuilder.
    • build

      public Alert build()
      Builds and returns an instance of the Alert class.

      Intermediate builder methods are not evaluated until the build method is called; in other words, they are evaluated lazily.

      Returns:
      new instance of the Alert class
    • apply

      public AlertBuilder apply(Consumer<Alert> func)
      Applies a function to the Alert instance being constructed. Most operations on the instance can be performed using this method.
      Returns:
      builder instance
    • alertType

      public AlertBuilder alertType(Alert.AlertType alertType)
      A builder method that invokes the setAlertType method on the instance being constructed.
      Returns:
      builder instance
    • contentText

      public AlertBuilder contentText(String contentText)
      A builder method that invokes the setContentText method on the instance being constructed.
      Returns:
      builder instance
    • dialogPane

      public AlertBuilder dialogPane(DialogPane value)
      A builder method that invokes the setDialogPane method on the instance being constructed.
      Returns:
      builder instance
    • graphic

      public AlertBuilder graphic(Node graphic)
      A builder method that invokes the setGraphic method on the instance being constructed.
      Returns:
      builder instance
    • headerText

      public AlertBuilder headerText(String headerText)
      A builder method that invokes the setHeaderText method on the instance being constructed.
      Returns:
      builder instance
    • height

      public AlertBuilder height(double height)
      A builder method that invokes the setHeight method on the instance being constructed.
      Returns:
      builder instance
    • onCloseRequest

      public AlertBuilder onCloseRequest(EventHandler<DialogEvent> value)
      A builder method that invokes the setOnCloseRequest method on the instance being constructed.
      Returns:
      builder instance
    • onHidden

      public AlertBuilder onHidden(EventHandler<DialogEvent> value)
      A builder method that invokes the setOnHidden method on the instance being constructed.
      Returns:
      builder instance
    • onHiding

      public AlertBuilder onHiding(EventHandler<DialogEvent> value)
      A builder method that invokes the setOnHiding method on the instance being constructed.
      Returns:
      builder instance
    • onShowing

      public AlertBuilder onShowing(EventHandler<DialogEvent> value)
      A builder method that invokes the setOnShowing method on the instance being constructed.
      Returns:
      builder instance
    • onShown

      public AlertBuilder onShown(EventHandler<DialogEvent> value)
      A builder method that invokes the setOnShown method on the instance being constructed.
      Returns:
      builder instance
    • resizable

      public AlertBuilder resizable(boolean resizable)
      A builder method that invokes the setResizable method on the instance being constructed.
      Returns:
      builder instance
    • result

      public AlertBuilder result(ButtonType value)
      A builder method that invokes the setResult method on the instance being constructed.
      Returns:
      builder instance
    • resultConverter

      public AlertBuilder resultConverter(Callback<ButtonType,ButtonType> value)
      A builder method that invokes the setResultConverter method on the instance being constructed.
      Returns:
      builder instance
    • title

      public AlertBuilder title(String title)
      A builder method that invokes the setTitle method on the instance being constructed.
      Returns:
      builder instance
    • width

      public AlertBuilder width(double width)
      A builder method that invokes the setWidth method on the instance being constructed.
      Returns:
      builder instance
    • x

      public AlertBuilder x(double x)
      A builder method that invokes the setX method on the instance being constructed.
      Returns:
      builder instance
    • y

      public AlertBuilder y(double y)
      A builder method that invokes the setY method on the instance being constructed.
      Returns:
      builder instance
    • addButtonTypes

      public final AlertBuilder addButtonTypes(ButtonType... elements)
      Calls the addAll method on the ObservableList returned by the Alert#getButtonTypes() method.
      Returns:
      builder instance
    • addButtonTypes

      public final AlertBuilder addButtonTypes(Collection<? extends ButtonType> col)
      Calls the addAll method on the ObservableList returned by the Alert#getButtonTypes() method.
      Returns:
      builder instance
    • alertTypePropertyApply

      public AlertBuilder alertTypePropertyApply(Consumer<ObjectProperty<Alert.AlertType>> op)
      Applies a function to the alertTypeProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.alertTypeProperty().bind(anotherProperty))
      
      // Use shorthand form
      .alertTypePropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • contentTextPropertyApply

      public AlertBuilder contentTextPropertyApply(Consumer<StringProperty> op)
      Applies a function to the contentTextProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.contentTextProperty().bind(anotherProperty))
      
      // Use shorthand form
      .contentTextPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • dialogPanePropertyApply

      public AlertBuilder dialogPanePropertyApply(Consumer<ObjectProperty<DialogPane>> op)
      Applies a function to the dialogPaneProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.dialogPaneProperty().bind(anotherProperty))
      
      // Use shorthand form
      .dialogPanePropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • graphicPropertyApply

      public AlertBuilder graphicPropertyApply(Consumer<ObjectProperty<Node>> op)
      Applies a function to the graphicProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.graphicProperty().bind(anotherProperty))
      
      // Use shorthand form
      .graphicPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • headerTextPropertyApply

      public AlertBuilder headerTextPropertyApply(Consumer<StringProperty> op)
      Applies a function to the headerTextProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.headerTextProperty().bind(anotherProperty))
      
      // Use shorthand form
      .headerTextPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • heightPropertyApply

      public AlertBuilder heightPropertyApply(Consumer<ReadOnlyDoubleProperty> op)
      Applies a function to the heightProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.heightProperty().bind(anotherProperty))
      
      // Use shorthand form
      .heightPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • onCloseRequestPropertyApply

      public AlertBuilder onCloseRequestPropertyApply(Consumer<ObjectProperty<EventHandler<DialogEvent>>> op)
      Applies a function to the onCloseRequestProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.onCloseRequestProperty().bind(anotherProperty))
      
      // Use shorthand form
      .onCloseRequestPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • onHiddenPropertyApply

      public AlertBuilder onHiddenPropertyApply(Consumer<ObjectProperty<EventHandler<DialogEvent>>> op)
      Applies a function to the onHiddenProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.onHiddenProperty().bind(anotherProperty))
      
      // Use shorthand form
      .onHiddenPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • onHidingPropertyApply

      public AlertBuilder onHidingPropertyApply(Consumer<ObjectProperty<EventHandler<DialogEvent>>> op)
      Applies a function to the onHidingProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.onHidingProperty().bind(anotherProperty))
      
      // Use shorthand form
      .onHidingPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • onShowingPropertyApply

      public AlertBuilder onShowingPropertyApply(Consumer<ObjectProperty<EventHandler<DialogEvent>>> op)
      Applies a function to the onShowingProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.onShowingProperty().bind(anotherProperty))
      
      // Use shorthand form
      .onShowingPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • onShownPropertyApply

      public AlertBuilder onShownPropertyApply(Consumer<ObjectProperty<EventHandler<DialogEvent>>> op)
      Applies a function to the onShownProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.onShownProperty().bind(anotherProperty))
      
      // Use shorthand form
      .onShownPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • resizablePropertyApply

      public AlertBuilder resizablePropertyApply(Consumer<BooleanProperty> op)
      Applies a function to the resizableProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.resizableProperty().bind(anotherProperty))
      
      // Use shorthand form
      .resizablePropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • resultConverterPropertyApply

      public AlertBuilder resultConverterPropertyApply(Consumer<ObjectProperty<Callback<ButtonType,ButtonType>>> op)
      Applies a function to the resultConverterProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.resultConverterProperty().bind(anotherProperty))
      
      // Use shorthand form
      .resultConverterPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • resultPropertyApply

      public AlertBuilder resultPropertyApply(Consumer<ObjectProperty<ButtonType>> op)
      Applies a function to the resultProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.resultProperty().bind(anotherProperty))
      
      // Use shorthand form
      .resultPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • showingPropertyApply

      public AlertBuilder showingPropertyApply(Consumer<ReadOnlyBooleanProperty> op)
      Applies a function to the showingProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.showingProperty().bind(anotherProperty))
      
      // Use shorthand form
      .showingPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • titlePropertyApply

      public AlertBuilder titlePropertyApply(Consumer<StringProperty> op)
      Applies a function to the titleProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.titleProperty().bind(anotherProperty))
      
      // Use shorthand form
      .titlePropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • widthPropertyApply

      public AlertBuilder widthPropertyApply(Consumer<ReadOnlyDoubleProperty> op)
      Applies a function to the widthProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.widthProperty().bind(anotherProperty))
      
      // Use shorthand form
      .widthPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • xPropertyApply

      public AlertBuilder xPropertyApply(Consumer<ReadOnlyDoubleProperty> op)
      Applies a function to the xProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.xProperty().bind(anotherProperty))
      
      // Use shorthand form
      .xPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • yPropertyApply

      public AlertBuilder yPropertyApply(Consumer<ReadOnlyDoubleProperty> op)
      Applies a function to the yProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.yProperty().bind(anotherProperty))
      
      // Use shorthand form
      .yPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • withButtonTypes

      public static AlertBuilder withButtonTypes(ButtonType... elements)
      Creates an instance of the builder, then calls the addAll(ButtonType... elements) method on the ObservableList returned by the Alert#getButtonTypes() method.

      After calling this method, you may need to invoke the alertType(AlertType) method. If you do not, the default AlertType.NONE will be set.

      Returns:
      builder instance
    • withButtonTypes

      public static AlertBuilder withButtonTypes(Collection<? extends ButtonType> col)
      Creates an instance of the builder, then calls the setAll(Collection<? extends ButtonType> col method on the ObservableList returned by the Alert#getButtonTypes() method.

      After calling this method, you may need to invoke the alertType(AlertType) method. If you do not, the default AlertType.NONE will be set.

      Returns:
      builder instance