Class NumberField

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants
Direct Known Subclasses:
DecimalField, IntegerField, ScientificField, TTrack.TrackNumberField

public class NumberField extends JTextField
A NumberField is a JTextField that formats and displays numbers. This default implementation displays very small and very large numbers in scientific notation and intermediate-value numbers in decimal form.
Version:
1.0
Author:
Douglas Brown
See Also:
  • Field Details

  • Constructor Details

    • NumberField

      public NumberField(int columns)
      Constructs a NumberField with default sigfigs (4)
      Parameters:
      columns - the number of character columns
    • NumberField

      public NumberField(int columns, int sigfigs)
      Constructs a NumberField with specified significant figures.
      Parameters:
      columns - the number of character columns
      sigfigs - the number of significant figures
    • NumberField

      public NumberField(int columns, int sigfigs, boolean fixed)
  • Method Details

    • getValue

      public double getValue()
      Gets the value from the text field.
      Returns:
      the value
    • format

      public final String format(double d)
    • setValue

      public void setValue(double value)
      Formats the specified value and enters it in the text field.
      Parameters:
      value - the value to be entered
    • setExpectedRange

      public void setExpectedRange(double lower, double upper)
      Sets the expected range of values for this number field. Note this does not set a firm max or min--only an expectation.
      Parameters:
      lower - the lower end of the range
      upper - the upper end of the range
    • setSigFigs

      public void setSigFigs(int sigfigs)
      Sets the number of significant figures for this number field.
      Parameters:
      sigfigs - the number of significant figures (between 2 and 6)
    • setMinValue

      public void setMinValue(double min)
      Sets a minimum value for this field.
      Parameters:
      min - the minimum allowed value
    • setMaxValue

      public void setMaxValue(double max)
      Sets a maximum value for this field.
      Parameters:
      max - the maximum allowed value
    • setUnits

      public void setUnits(String units)
      Sets the units.
      Parameters:
      units - the units
    • getUnits

      public String getUnits()
      Gets the units.
      Returns:
      units the units
    • setConversionFactor

      public void setConversionFactor(double factor)
    • getConversionFactor

      public double getConversionFactor()
    • applyPattern

      public void applyPattern(String p)
      Apply the specified pattern, retrieving the appropriate formatter
      Parameters:
      p -
    • setPatterns

      public void setPatterns(String[] patterns)
      Sets the patterns for this field. The patterns are applied as follows: value<0.1: patterns[0] value<10: patterns[1] value<100: patterns[2] value<1000: patterns[3] value>=1000: patterns[4]
      Parameters:
      patterns - the desired patterns
    • setPatterns

      public void setPatterns(String[] patterns, double[] limits)
      Sets the patterns and limits for this field. The patterns are applied as follows: value<limits[0]: patterns[0] value<limits[1]: patterns[1] value<limits[2]: patterns[2] value<limits[3]: patterns[3] value>=limits[3]: patterns[4]
      Parameters:
      patterns - the desired patterns
      limits - the limits that determine which pattern to use
    • setFixedPattern

      public void setFixedPattern(String pattern)
      Sets a fixed user pattern.
      Parameters:
      pattern - the desired pattern (may be null)
    • getFixedPattern

      public String getFixedPattern()
      Gets the fixed user pattern.
      Returns:
      the pattern
    • setParseIntegerOnly

      public void setParseIntegerOnly()
    • setFormatFor

      public void setFormatFor(double d)
    • refreshDecimalSeparators

      public void refreshDecimalSeparators(boolean redraw)