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)
-
Slider(int, int, int)
- Construct a slider with the specified min, max
and initial values.
-
Slider(int, int, int, int)
- Construct a slider with the specified min, max,
and initial values, plus the specified "bubble"
(thumb) value.
-
action(Event, Object)
- When textfield changes, sets the scrollbar
-
doAction(int)
- A place holder to override for action to be taken
when scrollbar changes
-
getFont()
- Returns the Font being used by the textfield.
-
getFontSize()
- The size of the current font
-
getMargins()
- Sometimes horizontal scrollbars look odd if they
are very tall.
-
getPreferredWidth()
- To keep scrollbars legible, a minimum width is
set.
-
getScrollbar()
- Returns the Scrollbar part of the Slider.
-
getText()
- Returns the current textfield string.
-
getTextField()
- Returns the TextField part of the Slider
-
getValue()
- This returns the current scrollbar value
-
handleEvent(Event)
- When scrollbar changes, sets the textfield
-
isEditable()
- Determines if the textfield is editable.
-
minimumSize()
- This just calls preferredSize
-
preferredSize()
- Changes the preferredSize to take a minimum
width, since super-tiny scrollbars are
hard to manipulate.
-
setEditable(boolean)
- Determines if you can enter values directly
into the textfield to change the scrollbar.
-
setFont(Font)
- Changes the Font being used by the textfield.
-
setFontSize(int)
- Rather than setting the whole font, you can
just set the size (Courier bold will be used
for the family/face).
-
setMargins(int)
- Sometimes horizontal scrollbars look odd if they
are very tall.
-
setPreferredWidth(int)
- To keep scrollbars legible, a minimum width is
set.
-
setText(String)
- This sets the TextField value directly.
-
setValue(int)
- This assigns the scrollbar value.
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.
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.
doAction
public void doAction(int value)
- A place holder to override for action to be taken
when scrollbar changes
handleEvent
public boolean handleEvent(Event event)
- When scrollbar changes, sets the textfield
- Overrides:
- handleEvent in class Component
action
public boolean action(Event event,
Object object)
- When textfield changes, sets the scrollbar
- Overrides:
- action in class Component
getScrollbar
public Scrollbar getScrollbar()
- Returns the Scrollbar part of the Slider.
getTextField
public TextField getTextField()
- Returns the TextField part of the Slider
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
minimumSize
public Dimension minimumSize()
- This just calls preferredSize
- Overrides:
- minimumSize in class Container
getPreferredWidth
public int getPreferredWidth()
- To keep scrollbars legible, a minimum width is
set. This returns the current value (default is
150).
- See Also:
- setPreferredWidth
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
getValue
public int getValue()
- This returns the current scrollbar value
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.
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
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
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.
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.
getFont
public Font getFont()
- Returns the Font being used by the textfield.
Courier bold 12 is the default.
- Overrides:
- getFont in class Component
setFont
public void setFont(Font textFieldFont)
- Changes the Font being used by the textfield.
- Overrides:
- setFont in class Component
getFontSize
public int getFontSize()
- The size of the current font
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).
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
setEditable
public void setEditable(boolean editable)
- Determines if you can enter values directly
into the textfield to change the scrollbar.
- See Also:
- isEditable