Class UDCNumericField

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

public class UDCNumericField extends JTextField
A JTextField which only allows a numeric value (a long) as input and performs very simple range validation on that value. This is accomplished by responding to FocusEvents. When focus is lost, the current value of the text field is compared against the minimum and maximum values specified. If the value is below the current minimum, then the contents will reflect the minimum value. If the value is above the current maximum value, then the maximum value will be displayed.
Since:
3.1
See Also:
  • Constructor Details

    • UDCNumericField

      public UDCNumericField()
      Default constructor for the class. By default, the minimum allowable value is 0, and maximum value is Long.MAX_VALUE.
    • UDCNumericField

      public UDCNumericField(int i)
      Calls parent constructor with the given value.
    • UDCNumericField

      public UDCNumericField(String s)
      Constructs field and initializes it with the given text.
  • Method Details

    • setText

      public void setText(String s)
      Verifies that the given String is a numeric value before calling parent setText() method. If the value is not numeric, the minimum value is used (by default, this is 0).
      Overrides:
      setText in class JTextComponent
      Parameters:
      s - Value to be displayed in the text field.
    • setMax

      public void setMax(long maxValue)
      Sets the maximum allowable value for this text field. If the current contents of the text field are greater than maxValue, the contents will be set to the new maximum. By default, the minimum value is Long.MAX_VALUE. If the user subsequently enters a value that is greater than the maximum value specified, the maximum value will be displayed upon receipt of a focusLost event.
    • setMin

      public void setMin(long minValue)
      Sets the minimum allowable value for this text field. If the current contents of the text field are less than minValue, the contents will be set to the new minimum. By default, the minimum value is 0. If the user subsequently enters a value that is less than the minimum value specified, the minimum value will be displayed upon receipt of a focusLost event.
    • setLong

      public void setLong(long l)
      Sets the contents of this text field to the given long value. If the value specified is below the current minimum value or above the current maximum value, the minimum or maximum value will be displayed, respectively.
    • setInt

      public void setInt(int i)
      Sets the contents of this text field to the given int value. If the value specified is below the current minimum value or above the current maximum value, the minimum or maximum value will be displayed, respectively.
    • getInt

      public int getInt()
      Returns the contents of this text field as an int. If the contents do not contain a valid int value, -1 is returned.
    • getLong

      public long getLong()
      Returns the contents of this text field as an int. If the contents do not contain a valid int value, -1 is returned.
    • processFocusEvent

      protected void processFocusEvent(FocusEvent e)
      Responds to FocusEvent.FOCUS_LOST events. When this type of event is received, the current contents of the text field are evaluated against the current minimum and maximum. If the value falls outside of these two values, then the minimum or maximum value is used. If the value is non-numeric, the minimum value will be displayed.
      Overrides:
      processFocusEvent in class Component