Class IntegerTextField

All Implemented Interfaces:
CyclerListener, FocusListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, Scrollable, SwingConstants

public class IntegerTextField extends ValidatedTextField
A textfield that accepts numeric data only. Decimal/fractional input is rejected - the number represented by this textfield must be an integer.
See Also:
  • Constructor Details

    • IntegerTextField

      public IntegerTextField()
      Constructs a new IntegerTextField. The number of columns is set to 10. The default minimum value allowed (when in a SpinnerField) is 0, and the maximum value is 100.
    • IntegerTextField

      public IntegerTextField(int cols)
      Constructs a new IntegerTextField containing the specified number of columns. The default minimum value allowed (when in a SpinnerField) is 0, and the maximum value is 100.
      Parameters:
      columns - the number of columns to use to calculate the preferred width.
  • Method Details

    • setText

      public void setText(String str)
      Sets the text of this textfield to the specified text, granted the specified text contains numeric data only. If the specified text contains alphabetic characters (including the currency symbol and/or the grouping separator) the text is rejected.
      Overrides:
      setText in class JTextComponent
      Parameters:
      str - the new text to display
    • coalesceEvents

      public boolean coalesceEvents()
    • replaceSelection

      public void replaceSelection(String str)
      Replaces the currently selected content with the specified text, granted the specified text contains numeric data only. If the specified text contains alphabetic characters the text is rejected. If there is no selection this amounts to an insert of the specified text.
      Overrides:
      replaceSelection in class JTextComponent
      Parameters:
      str - the text to use when replacing the selected text
    • getValue

      public Object getValue()
      Used to retrieve the value of component as an Integer instead of a String (using getText()). Note that you may get a NumberFormatException if the number represented in the textfield exceeds the maximum Integer value. If that is the case, you may choose to retrieve the number as a String instead.
      Specified by:
      getValue in class ValidatedTextField
      Returns:
      the numeric value of the component
    • valueChange

      public void valueChange(CyclerEvent e)
      Called when this component is embedded in a SpinnerField and the associated Cycler is selected.
      Specified by:
      valueChange in interface CyclerListener
      Specified by:
      valueChange in class ValidatedTextField
      Parameters:
      e - the CyclerEvent
    • setMaximumValue

      public void setMaximumValue(int max)
      Sets the minimum value allowed when spinning up. This only pertains to spinning. We eventually need to fold this limit into the text input area as well.
      Parameters:
      max - the max value
    • getMaximumValue

      public int getMaximumValue()
      Gets the maximum value allowed when spinning up
      Returns:
      the max value
    • setMinimumValue

      public void setMinimumValue(int min)
      Sets the minimum value allowed when spinning up. This only pertains to spinning. We eventually need to fold this limit into the text input area as well.
    • getMinimumValue

      public int getMinimumValue()
      Gets the minimum value allowed when spinning up.
      Returns:
      the min value
    • setAllowEmptyValue

      public void setAllowEmptyValue(boolean b)
      If true, the textfield appears initially empty and getText() will return am empty string. Otherwise, the textfield will have an initial value of the minimum value.
      This is initially false;
      Parameters:
      b - Determines the state
    • setNumDigitsAllowed

      public void setNumDigitsAllowed(int len)
      Establishes the maximum number of digits allowed in this textfield Note that if the resulting number exceeds the maximum value of an Integer you will not be able to retrieve the value as an Integer.
      The default is 10.
      Parameters:
      len -
    • getNumDigitsAllowed

      public int getNumDigitsAllowed()
    • addNotify

      public void addNotify()
      Overrides:
      addNotify in class JComponent