Class Slider

Class Slider

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----Slider

public class Slider
extends Panel
A class that combines a horizontal Scrollbar and a TextField (to the right of the Scrollbar). The TextField shows the current scrollbar value, plus, if setEditable(true) is set, it can be used to change the value as well.
Author:
Marty Hall (hall@apl.jhu.edu)

Constructor Index

 o Slider(int, int, int)
Construct a slider with the specified min, max and initial values.
 o Slider(int, int, int, int)
Construct a slider with the specified min, max, and initial values, plus the specified "bubble" (thumb) value.

Method Index

 o action(Event, Object)
When textfield changes, sets the scrollbar
 o doAction(int)
A place holder to override for action to be taken when scrollbar changes
 o getFont()
Returns the Font being used by the textfield.
 o getFontSize()
The size of the current font
 o getMargins()
Sometimes horizontal scrollbars look odd if they are very tall.
 o getPreferredWidth()
To keep scrollbars legible, a minimum width is set.
 o getScrollbar()
Returns the Scrollbar part of the Slider.
 o getText()
Returns the current textfield string.
 o getTextField()
Returns the TextField part of the Slider
 o getValue()
This returns the current scrollbar value
 o handleEvent(Event)
When scrollbar changes, sets the textfield
 o isEditable()
Determines if the textfield is editable.
 o minimumSize()
This just calls preferredSize
 o preferredSize()
Changes the preferredSize to take a minimum width, since super-tiny scrollbars are hard to manipulate.
 o setEditable(boolean)
Determines if you can enter values directly into the textfield to change the scrollbar.
 o setFont(Font)
Changes the Font being used by the textfield.
 o setFontSize(int)
Rather than setting the whole font, you can just set the size (Courier bold will be used for the family/face).
 o setMargins(int)
Sometimes horizontal scrollbars look odd if they are very tall.
 o setPreferredWidth(int)
To keep scrollbars legible, a minimum width is set.
 o setText(String)
This sets the TextField value directly.
 o setValue(int)
This assigns the scrollbar value.

Constructors

 o Slider
  public Slider(int minValue,
                int maxValue,
                int initialValue)
Construct a slider with the specified min, max and initial values. The "bubble" (thumb) size is set to 1/10th the scrollbar range. In JDK 1.1.x, it tries to adjust for the max value bug by adding the bubble thickness to the max value.
 o Slider
  public Slider(int minValue,
                int maxValue,
                int initialValue,
                int bubbleSize)
Construct a slider with the specified min, max, and initial values, plus the specified "bubble" (thumb) value. This bubbleSize should be specified in the units that min and max use, not in pixels. Thus, if min is 20 and max is 320, then a bubbleSize of 30 is 10% of the visible range.

Methods

 o doAction
  public void doAction(int value)
A place holder to override for action to be taken when scrollbar changes
 o handleEvent
  public boolean handleEvent(Event event)
When scrollbar changes, sets the textfield
Overrides:
handleEvent in class Component
 o action
  public boolean action(Event event,
                        Object object)
When textfield changes, sets the scrollbar
Overrides:
action in class Component
 o getScrollbar
  public Scrollbar getScrollbar()
Returns the Scrollbar part of the Slider.
 o getTextField
  public TextField getTextField()
Returns the TextField part of the Slider
 o preferredSize
  public Dimension preferredSize()
Changes the preferredSize to take a minimum width, since super-tiny scrollbars are hard to manipulate.
Overrides:
preferredSize in class Container
See Also:
getPreferredWidth, setPreferredWidth
 o minimumSize
  public Dimension minimumSize()
This just calls preferredSize
Overrides:
minimumSize in class Container
 o getPreferredWidth
  public int getPreferredWidth()
To keep scrollbars legible, a minimum width is set. This returns the current value (default is 150).
See Also:
setPreferredWidth
 o setPreferredWidth
  public void setPreferredWidth(int preferredWidth)
To keep scrollbars legible, a minimum width is set. This sets the current value (default is 150).
See Also:
getPreferredWidth
 o getValue
  public int getValue()
This returns the current scrollbar value
 o setValue
  public void setValue(int value)
This assigns the scrollbar value. If it is below the minimum value or above the maximum, the value is set to the min and max value, respectively.
 o getMargins
  public int getMargins()
Sometimes horizontal scrollbars look odd if they are very tall. So empty top/bottom margins can be set. This returns the margin setting. The default is four.
See Also:
setMargins
 o setMargins
  public void setMargins(int margins)
Sometimes horizontal scrollbars look odd if they are very tall. So empty top/bottom margins can be set. This sets the margin setting.
See Also:
getMargins
 o getText
  public String getText()
Returns the current textfield string. In most cases this is just the same as a String version of getValue, except that there may be padded blank spaces at the left.
 o setText
  public void setText(String text)
This sets the TextField value directly. Use with extreme caution since it does not right-align or check if value is numeric.
 o getFont
  public Font getFont()
Returns the Font being used by the textfield. Courier bold 12 is the default.
Overrides:
getFont in class Component
 o setFont
  public void setFont(Font textFieldFont)
Changes the Font being used by the textfield.
Overrides:
setFont in class Component
 o getFontSize
  public int getFontSize()
The size of the current font
 o setFontSize
  public void setFontSize(int size)
Rather than setting the whole font, you can just set the size (Courier bold will be used for the family/face).
 o isEditable
  public boolean isEditable()
Determines if the textfield is editable. If it is, you can enter a number to change the scrollbar value. In such a case, entering a value outside the legal range results in the min or max legal value. A non-integer is ignored.
See Also:
setEditable
 o setEditable
  public void setEditable(boolean editable)
Determines if you can enter values directly into the textfield to change the scrollbar.
See Also:
isEditable