Class NumberField<T extends Number>

Type Parameters:
T - the Number type
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

public final class NumberField<T extends Number> extends HintTextField
A text field for numbers. Use builder(Class) or builder(Class, Value) for NumberField.Builder instances.
See Also:
  • Field Details

    • CONVERT_GROUPING_TO_DECIMAL_SEPARATOR

      public static final PropertyValue<Boolean> CONVERT_GROUPING_TO_DECIMAL_SEPARATOR
      Specifies whether NumberFields should convert a grouping separator symbol to a decimal separator symbol when typed. This solves the problem of locale controlling whether the numpad comma acts as a decimal symbol, which is usually what we want.
      • Value type: Boolean
      • Default value: true
  • Method Details

    • setDocument

      public void setDocument(Document doc)
      Overrides:
      setDocument in class JTextField
    • setGroupingUsed

      public void setGroupingUsed(boolean groupingUsed)
      Set whether grouping will be used in this field.
      Parameters:
      groupingUsed - true if grouping should be used false otherwise
    • setValueRange

      public void setValueRange(Number minimumValue, Number maximumValue)
      Sets the range of values this field should allow
      Parameters:
      minimumValue - the minimum value
      maximumValue - the maximum value
    • setMinimumValue

      public void setMinimumValue(Number minimumValue)
      Parameters:
      minimumValue - the minimum value
    • getMinimumValue

      public Number getMinimumValue()
      Returns:
      the minimum value this field should accept
    • setMaximumValue

      public void setMaximumValue(Number maximumValue)
      Parameters:
      maximumValue - the maximum value
    • getMaximumValue

      public Number getMaximumValue()
      Returns:
      the maximum value this field should accept
    • setSeparators

      public void setSeparators(char decimalSeparator, char groupingSeparator)
      Set the decimal and grouping separators for this field
      Parameters:
      decimalSeparator - the decimal separator
      groupingSeparator - the grouping separator
      Throws:
      IllegalArgumentException - in case both separators are the same character
    • setDecimalSeparator

      public void setDecimalSeparator(char decimalSeparator)
      Sets the decimal separator
      Parameters:
      decimalSeparator - the separator
    • setGroupingSeparator

      public void setGroupingSeparator(char groupingSeparator)
      Sets the grouping separator
      Parameters:
      groupingSeparator - the separator
    • getMaximumFractionDigits

      public int getMaximumFractionDigits()
      Returns:
      the maximum number of fraction digits this field shows
      Throws:
      IllegalStateException - in case this NumberField is not based on a decimal type
    • setMaximumFractionDigits

      public void setMaximumFractionDigits(int maximumFractionDigits)
      Parameters:
      maximumFractionDigits - the maximum number of fraction digits this field shows
      Throws:
      IllegalStateException - in case this NumberField is not based on a decimal type
    • setConvertGroupingToDecimalSeparator

      public void setConvertGroupingToDecimalSeparator(boolean convertGroupingToDecimalSeparator)
      Specifies whether this number field should convert a grouping separator symbol to a decimal separator symbol when typed. This solves the problem of locale controlling whether the numpad comma acts as a decimal symbol, which is usually what we want. True by default.
      Parameters:
      convertGroupingToDecimalSeparator - true if grouping separators should be converted to decimal separators when typed
    • isConvertGroupingToDecimalSeparator

      public boolean isConvertGroupingToDecimalSeparator()
      Returns:
      true if grouping separators should be converted to decimal separators when typed
    • setSilentValidation

      public void setSilentValidation(boolean silentValidation)
      Default false.
      Parameters:
      silentValidation - true if invalid input should be silently prevented instead of throwing validation exceptions
    • isSilentValidation

      public boolean isSilentValidation()
      Returns:
      true if invalid input should be silently prevented instead of throwing validation exceptions
    • number

      public Mutable<T> number()
      Returns:
      a Mutable instance for the underlying number
    • builder

      public static <T extends Number> NumberField.Builder<T> builder(Class<T> valueClass)
      Type Parameters:
      T - the value type
      Parameters:
      valueClass - the value class
      Returns:
      a builder for a component
    • builder

      public static <T extends Number> NumberField.Builder<T> builder(Class<T> valueClass, Value<T> linkedValue)
      Type Parameters:
      T - the value type
      Parameters:
      valueClass - the value class
      linkedValue - the value to link to the component
      Returns:
      a builder for a component