Class JSpinField

All Implemented Interfaces:
ActionListener, FocusListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CaretListener, ChangeListener

JSpinField is a numeric field with 2 spin buttons to increase or decrease the value. It has the same interface as the "old" JSpinField but uses a JSpinner internally (since J2SE SDK 1.4) rather than a scrollbar for emulating the spin buttons.
Version:
$LastChangedRevision: 85 $, $LastChangedDate: 2006-04-28 13:50:52 +0200 (Fr, 28 Apr 2006) $
Author:
Kai Toedter
See Also:
  • Field Details

  • Constructor Details

    • JSpinField

      public JSpinField()
      Default JSpinField constructor. The valid value range is between Integer.MIN_VALUE and Integer.MAX_VALUE. The initial value is 0.
    • JSpinField

      public JSpinField(int min, int max)
      JSpinField constructor with given minimum and maximum vaues and initial value 0.
  • Method Details

    • adjustWidthToMaximumValue

    • stateChanged

      public void stateChanged(ChangeEvent e)
      Is invoked when the spinner model changes
      Specified by:
      stateChanged in interface ChangeListener
      Parameters:
      e - the ChangeEvent
    • setValue

      protected void setValue(int newValue, boolean updateTextField, boolean firePropertyChange)
      Sets the value attribute of the JSpinField object.
      Parameters:
      newValue - The new value
      updateTextField - true if text field should be updated
    • setValue

      public void setValue(int newValue)
      Sets the value. This is a bound property.
      Parameters:
      newValue - the new value
      See Also:
    • getValue

      public int getValue()
      Returns the value.
      Returns:
      the value value
    • setMinimum

      public void setMinimum(int newMinimum)
      Sets the minimum value.
      Parameters:
      newMinimum - the new minimum value
      See Also:
    • getMinimum

      public int getMinimum()
      Returns the minimum value.
      Returns:
      the minimum value
    • setMaximum

      public void setMaximum(int newMaximum)
      Sets the maximum value and adjusts the preferred width.
      Parameters:
      newMaximum - the new maximum value
      See Also:
    • setHorizontalAlignment

      public void setHorizontalAlignment(int alignment)
      Sets the horizontal alignment of the displayed value.
      Parameters:
      alignment - the horizontal alignment
    • getMaximum

      public int getMaximum()
      Returns the maximum value.
      Returns:
      the maximum value
    • setFont

      public void setFont(Font font)
      Sets the font property.
      Overrides:
      setFont in class JComponent
      Parameters:
      font - the new font
    • setForeground

      public void setForeground(Color fg)
      Sets the foreground
      Overrides:
      setForeground in class JComponent
      Parameters:
      fg - the foreground
    • caretUpdate

      public void caretUpdate(CaretEvent e)
      After any user input, the value of the textfield is proofed. Depending on being an integer, the value is colored green or red.
      Specified by:
      caretUpdate in interface CaretListener
      Parameters:
      e - the caret event
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      After any user input, the value of the textfield is proofed. Depending on being an integer, the value is colored green or red. If the textfield is green, the enter key is accepted and the new value is set.
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - Description of the Parameter
    • setEnabled

      public void setEnabled(boolean enabled)
      Enable or disable the JSpinField.
      Overrides:
      setEnabled in class JComponent
      Parameters:
      enabled - The new enabled value
    • getSpinner

      Returns the year chooser's spinner (which allow the focus to be set to it).
      Returns:
      Component the spinner or null, if the month chooser has no spinner
    • main

      public static void main(String[] s)
      Creates a JFrame with a JSpinField inside and can be used for testing.
      Parameters:
      s - The command line arguments
    • focusGained

      public void focusGained(FocusEvent e)
      Specified by:
      focusGained in interface FocusListener
    • focusLost

      public void focusLost(FocusEvent e)
      The value of the text field is checked against a valid (green) value. If valid, the value is set and a property change is fired.
      Specified by:
      focusLost in interface FocusListener