Class SpinButton
Class SpinButton
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----SpinButton
- public class SpinButton
- extends Panel
A custom Java component that provides a numerical spin button. The contents
of the TextField can be incremented or decremented by selecting the up or
down arrows. The current value can be overtyped if the component is not
set to be readonly.
IMPORTANT NOTE: On Windows platforms there is currently a problem with
updating the TextField while spinning. The spin is still occurring, however
and the display will be updated when the mouse button is released (although
sometimes even this doesn't happen in which case a single click on the up
or down button will refresh the display). It is anticipated that this
problem will be resolved in Java version 1.1.
-
SB_NUMERIC_ONLY
- Use this value to set the input style of the SpinButton to be numeric.
-
SpinButton()
- Construct a SpinButton object.
-
SpinButton(int)
- Construct a SpinButton object with the specified input type.
-
disable()
- Disables the SpinButton from input.
-
enable()
- Enables the SpinButton for input.
-
enable(boolean)
- Enables or disables the SpinButton for input depending on the boolean
condition.
-
getLower()
- Returns the current setting for the lower range value.
-
getUpper()
- Returns the current setting for the upper range value.
-
handleEvent(Event)
-
Handles scroll and keyboard events for the SpinButton.
-
inputTypeAllowed()
- Returns the data type permitted in the SpinButton.
-
intValue()
- Get the current numeric value of the SpinButton.
-
isReadOnly()
- Returns the current editable setting for the SpinButton.
-
minimumSize()
- Returns the recommended minimum size for the SpinButton.
-
preferredSize()
- Returns the preferred size for the SpinButton.
-
reshape(int, int, int, int)
- Changes the current position and size of the SpinButton.
-
setInputType(int)
- Changes the permitted input type for the SpinButton.
-
setRange(int, int)
- Changes the current minimum and maximum values for the spin range.
-
setReadOnly(boolean)
- Changes the current editable mode of the SpinButton.
-
setValue(int)
- Sets the current numeric value of the SpinButton regardless of the
validity of the number.
-
setValue(String)
- Sets the current text value of the SpinButton regardless of the
validity of the data.
-
spinDown(int)
- Spins the SpinButton down by the specified amount.
-
spinUp(int)
- Spins the SpinButton up by the specified amount.
SB_NUMERIC_ONLY
public final static int SB_NUMERIC_ONLY
- Use this value to set the input style of the SpinButton to be numeric.
- See Also:
- setInputType
SpinButton
public SpinButton()
- Construct a SpinButton object. It will create a SpinButton with an
SB_NUMERIC_ONLY input style by default.
- See Also:
- SB_NUMERIC_ONLY
SpinButton
public SpinButton(int input_type)
- Construct a SpinButton object with the specified input type.
- Parameters:
- input_type - The input type to set for the SpinButton.
- Throws: IllegalArgumentException
- Invalid SpinButton input type.
setInputType
public void setInputType(int input_type)
- Changes the permitted input type for the SpinButton.
- Parameters:
- input_type - The input type to set for the SpinButton.
- Throws: IllegalArgumentException
- Invalid SpinButton input type.
- See Also:
- SB_NUMERIC_ONLY
inputTypeAllowed
public int inputTypeAllowed()
- Returns the data type permitted in the SpinButton.
- Returns:
- The current data type.
- See Also:
- SB_NUMERIC_ONLY
setReadOnly
public void setReadOnly(boolean r_only)
- Changes the current editable mode of the SpinButton. A value of true will
make the field read only. A value of false will make it editable.
- Parameters:
- r_only - The edit mode to set.
isReadOnly
public boolean isReadOnly()
- Returns the current editable setting for the SpinButton. A value of true
means the field is read only. A value of false means the field is editable.
- Returns:
- The current edit mode.
setRange
public void setRange(int lower,
int upper)
- Changes the current minimum and maximum values for the spin range. This method
is only valid for integer SpinButtons of the type SB_NUMERIC_ONLY.
- Parameters:
- lower - The lower limit of the spin range.
- upper - The upper limit of the spin range.
- Throws: RuntimeException
- SpinButton not set to valid input type.
getLower
public int getLower()
- Returns the current setting for the lower range value. This method is only
valid for integer SpinButtons of the type SB_NUMERIC_ONLY.
- Returns:
- The current lower range value.
- Throws: RuntimeException
- SpinButton not set to valid input type.
getUpper
public int getUpper()
- Returns the current setting for the upper range value. This method is only
valid for integer SpinButtons of the type SB_NUMERIC_ONLY.
- Returns:
- The current upper range value.
- Throws: RuntimeException
- SpinButton not set to valid input type.
spinUp
public void spinUp(int spin_by)
- Spins the SpinButton up by the specified amount. If the spin up value would
cause the spin value to be larger than the maximum value, then the
spin button will be set to the maximum value. Negative numbers
are ignored.
- Parameters:
- spin_by - The number to spin the button up by.
spinDown
public void spinDown(int spin_by)
- Spins the SpinButton down by the specified amount. If the spin down value would
cause the spin value to be lower than the minimum value, then the
spin button will be set to the minimum value. Negative numbers
are ignored.
- Parameters:
- spin_by - The number to spin the button down by.
enable
public void enable()
- Enables the SpinButton for input.
- Overrides:
- enable in class Component
enable
public void enable(boolean cond)
- Enables or disables the SpinButton for input depending on the boolean
condition. A Value of true will enable the component, a value of false
will disable the component.
- Parameters:
- cond - Enable (true) or disable (false) the component.
- Overrides:
- enable in class Component
disable
public void disable()
- Disables the SpinButton from input.
- Overrides:
- disable in class Component
reshape
public synchronized void reshape(int x,
int y,
int width,
int height)
- Changes the current position and size of the SpinButton. The two buttons
will expand vertically to fill any space, but are of fixed width. The
TextField will expand both horizontally and vertically to fill the remaining
space.
- Parameters:
- x - The new position on the x axis.
- y - The new position on the y axis.
- width - The new width.
- height - The new height.
- Overrides:
- reshape in class Component
minimumSize
public Dimension minimumSize()
- Returns the recommended minimum size for the SpinButton. Used by layout
managers to determine the screen dimensions.
- Returns:
- A Dimension containing the minimum width and height.
- Overrides:
- minimumSize in class Container
preferredSize
public Dimension preferredSize()
- Returns the preferred size for the SpinButton. Used by layout
managers to determine the screen dimensions.
- Returns:
- A Dimension containing the preferred width and height.
- Overrides:
- preferredSize in class Container
setValue
public void setValue(int new_value)
- Sets the current numeric value of the SpinButton regardless of the
validity of the number.
- Parameters:
- new_value - The new number to put in the field.
setValue
public void setValue(String new_value)
- Sets the current text value of the SpinButton regardless of the
validity of the data. NOTE: This is a placeholder function until
alphanumeric support is added.
- Parameters:
- new_value - The new text to put in the field.
intValue
public int intValue()
- Get the current numeric value of the SpinButton.
- Returns:
- the current value of the SpinButton
handleEvent
public boolean handleEvent(Event event)
- Handles scroll and keyboard events for the SpinButton.
- Returns:
- True or false depending on whether the event has been handled or not.
- Overrides:
- handleEvent in class Component