Class JIntegerTextField

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

public class JIntegerTextField extends JTextField
JIntegerTextField, This implements a text field where it is only possible to type numbers into the field. The field will contain a valid integer at all times. The component has methods to get or set the value of the field as an integer, which will never throw a parsing exception. This component does not allow the field to be empty. The range of allowed numbers can be set by the programmer, within limits that are described below. The default range for this component is (Integer.MIN_VALUE to Integer.MAX_VALUE). You may optionally set a different minimum and maximum value for the number, within certain limits. Specifically, the chosen range must include all of the single-digit numbers from 1 through 9. For details on why this requirement is necessary for this component, see the "Single Digit Requirement Notes" below. If your usage requires a range outside of these specifications, then a JSpinner might be a possible alternative to consider. Single Digit Requirement Notes: The minimum and maximum values for this component must include the numbers 1 through 9, because otherwise this component would require a "commit or revert" type of functionality to handle all cases. For example, imagine the field is blank, the minimum value is 100, and a user types a "5". A JSpinner handles this situation by implementing a focus listener, and "reverting" to the minimum value of 100 if the component loses focus while it is in an invalid state. This component prevents the invalid state from being created in the first place. To summarize, allowing invalid states (or commit and revert) is outside the intended scope of this component.
See Also:
  • Field Details

  • Constructor Details

    • JIntegerTextField

      public JIntegerTextField()
    • JIntegerTextField

      public JIntegerTextField(int preferredWidthFromColumnCount)
  • Method Details

    • getDefaultValue

      public int getDefaultValue()
    • getMaximumValue

      public int getMaximumValue()
    • getMinimumValue

      public int getMinimumValue()
    • getValue

      public int getValue()
    • main

      public static void main(String[] args)
    • setMaximumValue

      public void setMaximumValue(int maximumValue)
    • setMinimumValue

      public void setMinimumValue(int minimumValue)
    • setValue

      public void setValue(int value)