com.toedter.components

Class JSpinField

Implemented Interfaces:
ActionListener, CaretListener, ChangeListener
Known Direct Subclasses:
JYearChooser

public class JSpinField
extends JPanel
implements ChangeListener, CaretListener, ActionListener

JSpinField2 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:
1.2
Author:
Kai Toedter

Field Summary

protected Color
darkGreen
protected int
max
protected int
min
protected JSpinner
spinner
protected JTextField
textField
the text (number) field
protected int
value

Constructor Summary

JSpinField()
Default JSpinField constructor.
JSpinField(int min, int max)
JSpinField constructor with given minimum and maximum vaues..

Method Summary

void
actionPerformed(ActionEvent e)
After any user input, the value of the textfield is proofed.
void
adjustWidthToMaximumValue()
void
caretUpdate(CaretEvent e)
After any user input, the value of the textfield is proofed.
int
getMaximum()
Returns the maximum value.
int
getMinimum()
Returns the minimum value.
String
getName()
Returns "JSpinField".
Component
getSpinner()
Returns the year chooser's spinner (which allow the focus to be set to it).
int
getValue()
Returns the value.
static void
main(String[] s)
Creates a JFrame with a JSpinField inside and can be used for testing.
void
setEnabled(boolean enabled)
Enable or disable the JSpinField.
void
setFont(Font font)
Sets the font property.
void
setForeground(Color fg)
DOCUMENT ME!
void
setHorizontalAlignment(int alignment)
Sets the horizontal alignment of the displayed value.
void
setMaximum(int newMaximum)
Sets the maximum value and adjusts the preferred width.
void
setMinimum(int newMinimum)
Sets the minimum value.
void
setValue(int newValue)
Sets the value.
protected void
setValue(int newValue, boolean updateTextField, boolean firePropertyChange)
Sets the value attribute of the JSpinField object.
void
stateChanged(ChangeEvent e)
Is invoked when the spinner model changes

Field Details

darkGreen

protected Color darkGreen

max

protected int max

min

protected int min

spinner

protected JSpinner spinner

textField

protected JTextField textField
the text (number) field

value

protected int value

Constructor Details

JSpinField

public JSpinField()
Default JSpinField constructor.

JSpinField

public JSpinField(int min,
                  int max)
JSpinField constructor with given minimum and maximum vaues..

Method Details

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.
Parameters:
e - Description of the Parameter

adjustWidthToMaximumValue

public void adjustWidthToMaximumValue()

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.
Parameters:
e - Description of the Parameter

getMaximum

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

getMinimum

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

getName

public String getName()
Returns "JSpinField".
Returns:
the name value

getSpinner

public Component 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

getValue

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

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

setEnabled

public void setEnabled(boolean enabled)
Enable or disable the JSpinField.
Parameters:
enabled - The new enabled value

setFont

public void setFont(Font font)
Sets the font property.
Parameters:
font - the new font

setForeground

public void setForeground(Color fg)
DOCUMENT ME!
Parameters:
fg - DOCUMENT ME!

setHorizontalAlignment

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

setMaximum

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

setMinimum

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

setValue

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

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

stateChanged

public void stateChanged(ChangeEvent e)
Is invoked when the spinner model changes
Parameters:
e - the ChangeEvent

Copyright B) 1999 - 2004 Kai Toedter.