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.


Variable Index

 o SB_NUMERIC_ONLY
Use this value to set the input style of the SpinButton to be numeric.

Constructor Index

 o SpinButton()
Construct a SpinButton object.
 o SpinButton(int)
Construct a SpinButton object with the specified input type.

Method Index

 o disable()
Disables the SpinButton from input.
 o enable()
Enables the SpinButton for input.
 o enable(boolean)
Enables or disables the SpinButton for input depending on the boolean condition.
 o getLower()
Returns the current setting for the lower range value.
 o getUpper()
Returns the current setting for the upper range value.
 o handleEvent(Event)
Handles scroll and keyboard events for the SpinButton.
 o inputTypeAllowed()
Returns the data type permitted in the SpinButton.
 o intValue()
Get the current numeric value of the SpinButton.
 o isReadOnly()
Returns the current editable setting for the SpinButton.
 o minimumSize()
Returns the recommended minimum size for the SpinButton.
 o preferredSize()
Returns the preferred size for the SpinButton.
 o reshape(int, int, int, int)
Changes the current position and size of the SpinButton.
 o setInputType(int)
Changes the permitted input type for the SpinButton.
 o setRange(int, int)
Changes the current minimum and maximum values for the spin range.
 o setReadOnly(boolean)
Changes the current editable mode of the SpinButton.
 o setValue(int)
Sets the current numeric value of the SpinButton regardless of the validity of the number.
 o setValue(String)
Sets the current text value of the SpinButton regardless of the validity of the data.
 o spinDown(int)
Spins the SpinButton down by the specified amount.
 o spinUp(int)
Spins the SpinButton up by the specified amount.

Variables

 o 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

Constructors

 o 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
 o 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.

Methods

 o 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
 o inputTypeAllowed
  public int inputTypeAllowed()
Returns the data type permitted in the SpinButton.
Returns:
The current data type.
See Also:
SB_NUMERIC_ONLY
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o enable
  public void enable()
Enables the SpinButton for input.
Overrides:
enable in class Component
 o 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
 o disable
  public void disable()
Disables the SpinButton from input.
Overrides:
disable in class Component
 o 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
 o 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
 o 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
 o 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.
 o 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.
 o intValue
  public int intValue()
Get the current numeric value of the SpinButton.
Returns:
the current value of the SpinButton
 o 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