Module MaterialFX

Class MFXSpinner<T>

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class MFXSpinner<T> extends Control
MaterialFX implementation of Spinner with a modern UI.

The spinner can work on any object you want but you will have to implement your own SpinnerModel. MaterialFX just like JavaFX offers 4 default models for: doubles, integers, local dates and lists.

Without a SpinnerModel the spinner is useless!

MFXSpinner offers the following features:

- You can set a prompt text for the field, promptTextProperty()

- You can set the spinner to be editable or not, editableProperty()

- You can allow/disallow the selection of the text, selectableProperty()

- You can specify the action to run when the spinner is editable and ENTER is pressed, onCommitProperty()

You can specify a function to transform the spinner's text. This can be useful for example when you want to add unit of measures to the text. The function carries the focus state of the editor (this way you can remove/add text according to the focus state) and the T value converted to a String

- You can easily change the orientation of the spinner, orientationProperty()

- You can easily change the icons, prevIconSupplierProperty(), nextIconSupplierProperty()

- You can specify the gap between the text and the icon, graphicTextGapProperty()

  • Property Details

  • Constructor Details

    • MFXSpinner

      public MFXSpinner()
    • MFXSpinner

      public MFXSpinner(SpinnerModel<T> spinnerModel)
  • Method Details

    • defaultIcons

      public void defaultIcons()
    • commit

      public void commit(String text)
      If the spinner is editable, editableProperty(), pressing the ENTER key will trigger the action specified by onCommitProperty().
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class Control
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class Region
    • getValue

      public T getValue()
      Gets the value of the property value.
      Property description:
      Specifies the current selected value for the spinner.

      Note that this property is read-only, you can set the value with setValue(Object) but it will fail with an exception if the spinnerModelProperty() is null.

    • valueProperty

      public ReadOnlyObjectProperty<T> valueProperty()
      Specifies the current selected value for the spinner.

      Note that this property is read-only, you can set the value with setValue(Object) but it will fail with an exception if the spinnerModelProperty() is null.

      See Also:
    • setValue

      public void setValue(T value)
      Sets the value of the property value.
      Property description:
      Specifies the current selected value for the spinner.

      Note that this property is read-only, you can set the value with setValue(Object) but it will fail with an exception if the spinnerModelProperty() is null.

    • getSpinnerModel

      public SpinnerModel<T> getSpinnerModel()
      Gets the value of the property spinnerModel.
      Property description:
      Specifies the spinner's model, responsible for handling the spinner's value according to the data type.
    • spinnerModelProperty

      public ObjectProperty<SpinnerModel<T>> spinnerModelProperty()
      Specifies the spinner's model, responsible for handling the spinner's value according to the data type.
      See Also:
    • setSpinnerModel

      public void setSpinnerModel(SpinnerModel<T> spinnerModel)
      Sets the value of the property spinnerModel.
      Property description:
      Specifies the spinner's model, responsible for handling the spinner's value according to the data type.
    • getPromptText

      public String getPromptText()
      Gets the value of the property promptText.
      Property description:
      Specifies the prompt text for the spinner's text field.
    • promptTextProperty

      public StringProperty promptTextProperty()
      Specifies the prompt text for the spinner's text field.
      See Also:
    • setPromptText

      public void setPromptText(String promptText)
      Sets the value of the property promptText.
      Property description:
      Specifies the prompt text for the spinner's text field.
    • isEditable

      public boolean isEditable()
      Gets the value of the property editable.
      Property description:
      Specifies whether the spinner's text field is editable.

      If you edit the text you must confirm the change by pressing the ENTER key, this will trigger the commit(String) method, more info here onCommitProperty().

    • editableProperty

      public BooleanProperty editableProperty()
      Specifies whether the spinner's text field is editable.

      If you edit the text you must confirm the change by pressing the ENTER key, this will trigger the commit(String) method, more info here onCommitProperty().

      See Also:
    • setEditable

      public void setEditable(boolean editable)
      Sets the value of the property editable.
      Property description:
      Specifies whether the spinner's text field is editable.

      If you edit the text you must confirm the change by pressing the ENTER key, this will trigger the commit(String) method, more info here onCommitProperty().

    • isSelectable

      public boolean isSelectable()
      Gets the value of the property selectable.
      Property description:
      Specifies whether the spinner's text is selectable.
    • selectableProperty

      public BooleanProperty selectableProperty()
      Specifies whether the spinner's text is selectable.
      See Also:
    • setSelectable

      public void setSelectable(boolean selectable)
      Sets the value of the property selectable.
      Property description:
      Specifies whether the spinner's text is selectable.
    • getOnCommit

      public Consumer<String> getOnCommit()
      Gets the value of the property onCommit.
      Property description:
      Specifies the action to perform when editing the spinner's text and confirming the changes by pressing ENTER.

      The action is a Consumer which carries the modified text. To change the spinner's value with that for example you probably want to validate the text, parse a valid T object and then set the value.

    • onCommitProperty

      public ConsumerProperty<String> onCommitProperty()
      Specifies the action to perform when editing the spinner's text and confirming the changes by pressing ENTER.

      The action is a Consumer which carries the modified text. To change the spinner's value with that for example you probably want to validate the text, parse a valid T object and then set the value.

      See Also:
    • setOnCommit

      public void setOnCommit(Consumer<String> onCommit)
      Sets the value of the property onCommit.
      Property description:
      Specifies the action to perform when editing the spinner's text and confirming the changes by pressing ENTER.

      The action is a Consumer which carries the modified text. To change the spinner's value with that for example you probably want to validate the text, parse a valid T object and then set the value.

    • getTextTransformer

      public BiFunction<Boolean,String,String> getTextTransformer()
      Gets the value of the property textTransformer.
      Property description:
      The text transformer is a BiFunction that allows you to change the spinner's text when the spinner's text field acquires/loses focus.

      This can be useful for example when you want to add the unit of measure to the spinner's text. Usually in such controls the unit of measure is added when the control is not focused and removed when editing the text.

      An example could be:
       
            MFXSpinner spinner = ...;
            spinner.setTextTransformer((focused, text) -> (!focused || !spinner.isEditable()) ? text + " meters" : text);
       
       
    • textTransformerProperty

      public BiFunctionProperty<Boolean,String,String> textTransformerProperty()
      The text transformer is a BiFunction that allows you to change the spinner's text when the spinner's text field acquires/loses focus.

      This can be useful for example when you want to add the unit of measure to the spinner's text. Usually in such controls the unit of measure is added when the control is not focused and removed when editing the text.

      An example could be:
       
            MFXSpinner spinner = ...;
            spinner.setTextTransformer((focused, text) -> (!focused || !spinner.isEditable()) ? text + " meters" : text);
       
       
      See Also:
    • setTextTransformer

      public void setTextTransformer(BiFunction<Boolean,String,String> textTransformer)
      Sets the value of the property textTransformer.
      Property description:
      The text transformer is a BiFunction that allows you to change the spinner's text when the spinner's text field acquires/loses focus.

      This can be useful for example when you want to add the unit of measure to the spinner's text. Usually in such controls the unit of measure is added when the control is not focused and removed when editing the text.

      An example could be:
       
            MFXSpinner spinner = ...;
            spinner.setTextTransformer((focused, text) -> (!focused || !spinner.isEditable()) ? text + " meters" : text);
       
       
    • getOrientation

      public Orientation getOrientation()
      Gets the value of the property orientation.
      Property description:
      Specifies the spinner's orientation.
    • orientationProperty

      public ObjectProperty<Orientation> orientationProperty()
      Specifies the spinner's orientation.
      See Also:
    • setOrientation

      public void setOrientation(Orientation orientation)
      Sets the value of the property orientation.
      Property description:
      Specifies the spinner's orientation.
    • getPrevIconSupplier

      public Supplier<Node> getPrevIconSupplier()
      Gets the value of the property prevIconSupplier.
      Property description:
      The Supplier used to build the icons which should trigger SpinnerModel.previous().

      Note that the defaultIcons() add the needed event handlers to use the SpinnerModel, it is not handled automatically!

    • prevIconSupplierProperty

      public SupplierProperty<Node> prevIconSupplierProperty()
      The Supplier used to build the icons which should trigger SpinnerModel.previous().

      Note that the defaultIcons() add the needed event handlers to use the SpinnerModel, it is not handled automatically!

      See Also:
    • setPrevIconSupplier

      public void setPrevIconSupplier(Supplier<Node> prevIconSupplier)
      Sets the value of the property prevIconSupplier.
      Property description:
      The Supplier used to build the icons which should trigger SpinnerModel.previous().

      Note that the defaultIcons() add the needed event handlers to use the SpinnerModel, it is not handled automatically!

    • getNextIconSupplier

      public Supplier<Node> getNextIconSupplier()
      Gets the value of the property nextIconSupplier.
      Property description:
      The Supplier used to build the icons which should trigger SpinnerModel.next().

      Note that the defaultIcons() add the needed event handlers to use the SpinnerModel, it is not handled automatically!

    • nextIconSupplierProperty

      public SupplierProperty<Node> nextIconSupplierProperty()
      The Supplier used to build the icons which should trigger SpinnerModel.next().

      Note that the defaultIcons() add the needed event handlers to use the SpinnerModel, it is not handled automatically!

      See Also:
    • setNextIconSupplier

      public void setNextIconSupplier(Supplier<Node> nextIconSupplier)
      Sets the value of the property nextIconSupplier.
      Property description:
      The Supplier used to build the icons which should trigger SpinnerModel.next().

      Note that the defaultIcons() add the needed event handlers to use the SpinnerModel, it is not handled automatically!

    • getGraphicTextGap

      public double getGraphicTextGap()
      Gets the value of the property graphicTextGap.
      Property description:
      Specifies the space between the spinner's text and the two icons.
    • graphicTextGapProperty

      public DoubleProperty graphicTextGapProperty()
      Specifies the space between the spinner's text and the two icons.
      See Also:
    • setGraphicTextGap

      public void setGraphicTextGap(double graphicTextGap)
      Sets the value of the property graphicTextGap.
      Property description:
      Specifies the space between the spinner's text and the two icons.