Class NumberInputField<T extends Number>

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
javafx.scene.control.TextInputControl
javafx.scene.control.TextField
com.dlsc.unitfx.CustomTextField
com.dlsc.unitfx.NumberInputField<T>
Type Parameters:
T - The type of number.
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable
Direct Known Subclasses:
DoubleInputField, IntegerInputField

public abstract class NumberInputField<T extends Number>
extends CustomTextField
Base control to number inputs, defines all base functionality to collect any object whose class is child of Number.
  • Property Summary

    Properties 
    Type Property Description
    javafx.beans.property.BooleanProperty allowNegatives
    Boolean property that tells the control to allow introducing a negative number.
    javafx.beans.property.ReadOnlyBooleanProperty invalid
    Property that indicates whether the value is valid after being validated by validator.
    javafx.beans.property.ObjectProperty<T> maximumValue
    The maximum value that can be entered in this field.
    javafx.beans.property.ObjectProperty<T> minimumValue
    The minimum value that can be entered in this field.
    javafx.beans.property.IntegerProperty numberOfDecimals
    The maximum digits in the decimal part of the number.
    javafx.beans.property.IntegerProperty numberOfIntegers
    The maximum digits in the integer part of the number.
    javafx.beans.property.ObjectProperty<Predicate<T>> validator
    Stores a validator object for the value converted from text entered.
    javafx.beans.property.ObjectProperty<T> value
    The number value representation of the text written.

    Properties inherited from class com.dlsc.unitfx.CustomTextField

    left, right

    Properties inherited from class javafx.scene.control.TextField

    alignment, onAction, prefColumnCount

    Properties inherited from class javafx.scene.control.TextInputControl

    anchor, caretPosition, editable, font, length, promptText, redoable, selectedText, selection, textFormatter, text, undoable

    Properties inherited from class javafx.scene.control.Control

    contextMenu, skin, tooltip

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
  • Nested Class Summary

    Nested classes/interfaces inherited from class javafx.scene.control.TextInputControl

    javafx.scene.control.TextInputControl.Content
  • Field Summary

    Fields inherited from class javafx.scene.control.TextField

    DEFAULT_PREF_COLUMN_COUNT

    Fields inherited from class javafx.scene.layout.Region

    USE_COMPUTED_SIZE, USE_PREF_SIZE

    Fields inherited from class javafx.scene.Node

    BASELINE_OFFSET_SAME_AS_HEIGHT
  • Constructor Summary

    Constructors 
    Constructor Description
    NumberInputField()
    Instances a new number input with with null value, no validator and allowing negatives.
  • Method Summary

    Modifier and Type Method Description
    javafx.beans.property.BooleanProperty allowNegativesProperty()
    Boolean property that tells the control to allow introducing a negative number.
    protected abstract String convertNumberToText​(T number)
    Converts the input number type object to string.
    protected abstract T convertTextToNumber​(String text)
    Converts the text to the input field number type object.
    T getMaximumValue()
    Gets the value of the property maximumValue.
    T getMinimumValue()
    Gets the value of the property minimumValue.
    int getNumberOfDecimals()
    Gets the value of the property numberOfDecimals.
    int getNumberOfIntegers()
    Gets the value of the property numberOfIntegers.
    Predicate<T> getValidator()
    Gets the value of the property validator.
    T getValue()
    Gets the value of the property value.
    javafx.beans.property.ReadOnlyBooleanProperty invalidProperty()
    Property that indicates whether the value is valid after being validated by validator.
    boolean isAllowNegatives()
    Gets the value of the property allowNegatives.
    boolean isInvalid()
    Gets the value of the property invalid.
    javafx.beans.property.ObjectProperty<T> maximumValueProperty()
    The maximum value that can be entered in this field.
    javafx.beans.property.ObjectProperty<T> minimumValueProperty()
    The minimum value that can be entered in this field.
    javafx.beans.property.IntegerProperty numberOfDecimalsProperty()
    The maximum digits in the decimal part of the number.
    javafx.beans.property.IntegerProperty numberOfIntegersProperty()
    The maximum digits in the integer part of the number.
    void setAllowNegatives​(boolean allowNegatives)
    Sets the value of the property allowNegatives.
    void setMaximumValue​(T maximumValue)
    Sets the value of the property maximumValue.
    void setMinimumValue​(T minimumValue)
    Sets the value of the property minimumValue.
    void setNumberOfDecimals​(int numberOfDecimals)
    Sets the value of the property numberOfDecimals.
    void setNumberOfIntegers​(int numberOfIntegers)
    Sets the value of the property numberOfIntegers.
    void setValidator​(Predicate<T> validator)
    Sets the value of the property validator.
    void setValue​(T value)
    Sets the value of the property value.
    javafx.beans.property.ObjectProperty<Predicate<T>> validatorProperty()
    Stores a validator object for the value converted from text entered.
    javafx.beans.property.ObjectProperty<T> valueProperty()
    The number value representation of the text written.

    Methods inherited from class com.dlsc.unitfx.CustomTextField

    createDefaultSkin, getLeft, getRight, leftProperty, rightProperty, setLeft, setRight

    Methods inherited from class javafx.scene.control.TextField

    alignmentProperty, getAlignment, getCharacters, getClassCssMetaData, getControlCssMetaData, getOnAction, getPrefColumnCount, onActionProperty, prefColumnCountProperty, setAlignment, setOnAction, setPrefColumnCount

    Methods inherited from class javafx.scene.control.TextInputControl

    anchorProperty, appendText, backward, cancelEdit, caretPositionProperty, clear, commitValue, copy, cut, deleteNextChar, deletePreviousChar, deleteText, deleteText, deselect, editableProperty, end, endOfNextWord, executeAccessibleAction, extendSelection, fontProperty, forward, getAnchor, getCaretPosition, getContent, getFont, getLength, getPromptText, getSelectedText, getSelection, getText, getText, getTextFormatter, home, insertText, isEditable, isRedoable, isUndoable, lengthProperty, nextWord, paste, positionCaret, previousWord, promptTextProperty, queryAccessibleAttribute, redo, redoableProperty, replaceSelection, replaceText, replaceText, selectAll, selectBackward, selectedTextProperty, selectEnd, selectEndOfNextWord, selectForward, selectHome, selectionProperty, selectNextWord, selectPositionCaret, selectPreviousWord, selectRange, setEditable, setFont, setPromptText, setText, setTextFormatter, textFormatterProperty, textProperty, undo, undoableProperty

    Methods inherited from class javafx.scene.control.Control

    computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty

    Methods inherited from class javafx.scene.layout.Region

    backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty

    Methods inherited from class javafx.scene.Parent

    getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds

    Methods inherited from class javafx.scene.Node

    accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.css.Styleable

    getStyleableNode
  • Property Details

  • Constructor Details

  • Method Details

    • convertTextToNumber

      protected abstract T convertTextToNumber​(String text)
      Converts the text to the input field number type object.
      Parameters:
      text - The text to be converted.
      Returns:
      In case of impossible conversion, return null instead of throwing exception.
    • convertNumberToText

      protected abstract String convertNumberToText​(T number)
      Converts the input number type object to string.
      Parameters:
      number - The number to be converted.
      Returns:
      If the number is null, then return empty string.
    • valueProperty

      public final javafx.beans.property.ObjectProperty<T> valueProperty()
      The number value representation of the text written.
      See Also:
      getValue(), setValue(T)
    • getValue

      public final T getValue()
      Gets the value of the property value.
      Property description:
      The number value representation of the text written.
    • setValue

      public final void setValue​(T value)
      Sets the value of the property value.
      Property description:
      The number value representation of the text written.
    • allowNegativesProperty

      public final javafx.beans.property.BooleanProperty allowNegativesProperty()
      Boolean property that tells the control to allow introducing a negative number.
      See Also:
      isAllowNegatives(), setAllowNegatives(boolean)
    • isAllowNegatives

      public final boolean isAllowNegatives()
      Gets the value of the property allowNegatives.
      Property description:
      Boolean property that tells the control to allow introducing a negative number.
    • setAllowNegatives

      public final void setAllowNegatives​(boolean allowNegatives)
      Sets the value of the property allowNegatives.
      Property description:
      Boolean property that tells the control to allow introducing a negative number.
    • validatorProperty

      public final javafx.beans.property.ObjectProperty<Predicate<T>> validatorProperty()
      Stores a validator object for the value converted from text entered. If the value entered is not valid, a pseudo class is added to the field, called ":invalid". This can be used for styling the field to indicate invalid inputs.
      See Also:
      getValidator(), setValidator(Predicate)
    • getValidator

      public final Predicate<T> getValidator()
      Gets the value of the property validator.
      Property description:
      Stores a validator object for the value converted from text entered. If the value entered is not valid, a pseudo class is added to the field, called ":invalid". This can be used for styling the field to indicate invalid inputs.
    • setValidator

      public final void setValidator​(Predicate<T> validator)
      Sets the value of the property validator.
      Property description:
      Stores a validator object for the value converted from text entered. If the value entered is not valid, a pseudo class is added to the field, called ":invalid". This can be used for styling the field to indicate invalid inputs.
    • invalidProperty

      public final javafx.beans.property.ReadOnlyBooleanProperty invalidProperty()
      Property that indicates whether the value is valid after being validated by validator.
      See Also:
      isInvalid()
    • isInvalid

      public final boolean isInvalid()
      Gets the value of the property invalid.
      Property description:
      Property that indicates whether the value is valid after being validated by validator.
    • numberOfIntegersProperty

      public final javafx.beans.property.IntegerProperty numberOfIntegersProperty()
      The maximum digits in the integer part of the number.
      See Also:
      getNumberOfIntegers(), setNumberOfIntegers(int)
    • getNumberOfIntegers

      public final int getNumberOfIntegers()
      Gets the value of the property numberOfIntegers.
      Property description:
      The maximum digits in the integer part of the number.
    • setNumberOfIntegers

      public final void setNumberOfIntegers​(int numberOfIntegers)
      Sets the value of the property numberOfIntegers.
      Property description:
      The maximum digits in the integer part of the number.
    • numberOfDecimalsProperty

      public final javafx.beans.property.IntegerProperty numberOfDecimalsProperty()
      The maximum digits in the decimal part of the number.
      See Also:
      getNumberOfDecimals(), setNumberOfDecimals(int)
    • getNumberOfDecimals

      public final int getNumberOfDecimals()
      Gets the value of the property numberOfDecimals.
      Property description:
      The maximum digits in the decimal part of the number.
    • setNumberOfDecimals

      public final void setNumberOfDecimals​(int numberOfDecimals)
      Sets the value of the property numberOfDecimals.
      Property description:
      The maximum digits in the decimal part of the number.
    • minimumValueProperty

      public final javafx.beans.property.ObjectProperty<T> minimumValueProperty()
      The minimum value that can be entered in this field. If this property is set, once the user enters a number lower than this minimum the field becomes invalid and the valueProperty() is set to null.
      See Also:
      getMinimumValue(), setMinimumValue(T)
    • getMinimumValue

      public final T getMinimumValue()
      Gets the value of the property minimumValue.
      Property description:
      The minimum value that can be entered in this field. If this property is set, once the user enters a number lower than this minimum the field becomes invalid and the valueProperty() is set to null.
    • setMinimumValue

      public final void setMinimumValue​(T minimumValue)
      Sets the value of the property minimumValue.
      Property description:
      The minimum value that can be entered in this field. If this property is set, once the user enters a number lower than this minimum the field becomes invalid and the valueProperty() is set to null.
    • maximumValueProperty

      public final javafx.beans.property.ObjectProperty<T> maximumValueProperty()
      The maximum value that can be entered in this field. If this property is set, once the user enters a number greater than this minimum the field becomes invalid and the valueProperty() is set to null.
      See Also:
      getMaximumValue(), setMaximumValue(T)
    • getMaximumValue

      public final T getMaximumValue()
      Gets the value of the property maximumValue.
      Property description:
      The maximum value that can be entered in this field. If this property is set, once the user enters a number greater than this minimum the field becomes invalid and the valueProperty() is set to null.
    • setMaximumValue

      public final void setMaximumValue​(T maximumValue)
      Sets the value of the property maximumValue.
      Property description:
      The maximum value that can be entered in this field. If this property is set, once the user enters a number greater than this minimum the field becomes invalid and the valueProperty() is set to null.