Class FloatingPointTextField

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

public class FloatingPointTextField extends JTextField
A simple text field for inputing floating point numbers. The field is continuously validated so that only valid characters and values can be entered. If the text is blank or contains only "-", ".", or "-.", the value is considered to be 0. You can optionally set a min and max value. In order for the continuous validation to work, the max must be a non-negative number and the min must be a non-positive number.
See Also:
  • Constructor Details

    • FloatingPointTextField

      public FloatingPointTextField(int columns)
      Constructs a new empty FloatingPointTextField.
      Parameters:
      columns - the number of columns for determining the preferred width
    • FloatingPointTextField

      public FloatingPointTextField(int columns, double initialValue)
      Constructs a new FloatingPointTextField initialized with the given value.
      Parameters:
      columns - the number of columns for determining the preferred width
  • Method Details

    • getValue

      public double getValue()
      Returns the value represented by the text in the field. If the field only contains "-",".", or "-.", the value returned will be 0.
      Returns:
      the value represented by the text in the field
    • setValue

      public void setValue(double value)
      Sets the text in the field to the given value.
      Parameters:
      value - the value to display in the text field
    • setMaxValue

      public void setMaxValue(double max)
      Sets the maximum allowed value. The max must be 0 or positive so that continuous validation can work.
      Parameters:
      max - the maximum allowed value.
    • setMinValue

      public void setMinValue(double min)
      Sets the minimum allowed value. The min must be 0 or negative so that continuous validation can work.
      Parameters:
      min - the minimum allowed value.