Class WholeNumbTextField

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants
Direct Known Subclasses:
PortTextField

public class WholeNumbTextField extends VTextField
Text field constrained to allow only non-negative integers.
See Also:
  • Constructor Details

    • WholeNumbTextField

      public WholeNumbTextField()
      Class constructor.
    • WholeNumbTextField

      public WholeNumbTextField(Document doc, String text, int ncols)
      Class constructor for a document model, initial string and field size.
      Parameters:
      doc - the document model (must be an AbstractDocument)
      text - the initial text
      ncols - the number of columns in the text field.
    • WholeNumbTextField

      public WholeNumbTextField(int ncols)
      Class constructor specifying the field size..
      Parameters:
      ncols - the number of columns in the text field.
    • WholeNumbTextField

      public WholeNumbTextField(String text)
      Class constructor giving an initial string.
      Parameters:
      text - the initial text
    • WholeNumbTextField

      public WholeNumbTextField(String text, int ncols)
      Class constructor giving an initial string and field size.
      Parameters:
      text - the initial text
      ncols - the number of columns in the text field.
  • Method Details

    • onAccepted

      protected void onAccepted() throws Exception
      Accept input. This method will be called when input is accepted, either by terminating the input with the "Enter" or "Return" key, or by changing the focus to another component in this application. Note that selecting a window in a separate application may not trigger this method.

      During error correction, this method may be called multiple times. That can also happen if the method VTextField.setText(String) is called. While this method can throw an exception, it is called in such a way that the exception will normally be caught by this class' methods and processed silently if at all.

      Note: if a subclass implements this method, it must call super.onAccepted(). If the text field is empty, the corresponding value is the default value, which can be set by calling setDefaultValue(int). The default value may be a negative number (e.g., to indicate that the field has not been set). Otherwise the text field's value (as an int) is used.

      Overrides:
      onAccepted in class VTextField
      Throws:
      Exception - an error occurred
    • setValue

      public void setValue(int value) throws IllegalArgumentException
      Set the value of the text field. The value must be non-negative. If a subclass imposes additional constraints on the value, it should override this method, perform a test to ensure that the value is allowed, throw an IllegalArgumentException if the test fails, and then call super.setValue(value).
      Parameters:
      value - the text-field's value.
      Throws:
      IllegalArgumentException - the argument is out of range.
    • getValue

      public int getValue()
      Get the text field's value. The value returned will not reflect any changes in the text field while it is being edited: the text field's value is updated when a loss of focus is detected or when the user explicitly uses the Return/Enter key.
      Returns:
      the value of the text field, or the default value when the text field is empty
      See Also:
    • setDefaultValue

      public void setDefaultValue(int value)
      Set the default value when the text-string is empty. The value may be any integer, although legal values will always be non-negative. This allows getValue to return a negative value as an indication that the field is empty: the default value can be any int.
      Parameters:
      value - the default value to use