|
JSR-209 (Final Release) | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JSlider
A component that lets the user graphically select a value by sliding
a knob within a bounded interval. The slider can show both
major tick marks and minor tick marks between them. The number of
values between the tick marks is controlled with
setMajorTickSpacing
and setMinorTickSpacing
.
For further information and examples see How to Use Sliders, a section in The Java Tutorial.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see java.beans.XMLEncoder
.
Field Summary | |
protected ChangeEvent |
changeEvent
Only one ChangeEvent is needed per slider instance since the
event's only (read-only) state is the source property. |
protected ChangeListener |
changeListener
The changeListener (no suffix) is the listener we add to the Sliders model. |
protected int |
majorTickSpacing
The number of values between the major tick marks -- the larger marks that break up the minor tick marks. |
protected int |
minorTickSpacing
The number of values between the minor tick marks -- the smaller marks that occur between the major tick marks. |
protected int |
orientation
|
protected BoundedRangeModel |
sliderModel
The data model that handles the numeric maximum value, minimum value, and current-position value for the slider. |
protected boolean |
snapToTicks
If true, the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob. |
Fields inherited from class javax.swing.JComponent |
listenerList, TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
JSlider()
Creates a horizontal slider with the range 0 to 100 and an initial value of 50. |
|
JSlider(BoundedRangeModel brm)
Creates a horizontal slider using the specified BoundedRangeModel. |
|
JSlider(int orientation)
Creates a slider using the specified orientation with the range 0 to 100 and an initial value of 50. |
|
JSlider(int min,
int max)
Creates a horizontal slider using the specified min and max with an initial value equal to the average of the min plus max. |
|
JSlider(int min,
int max,
int value)
Creates a horizontal slider using the specified min, max and value. |
|
JSlider(int orientation,
int min,
int max,
int value)
Creates a slider with the specified orientation and the specified minimum, maximum, and initial values. |
Method Summary | |
void |
addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider. |
protected ChangeListener |
createChangeListener()
Subclasses that want to handle model ChangeEvents differently can override this method to return their own ChangeListener implementation. |
java.util.Hashtable |
createStandardLabels(int increment)
Creates a hashtable that will draw text labels starting at the slider minimum using the increment specified. |
java.util.Hashtable |
createStandardLabels(int increment,
int start)
Creates a hashtable that will draw text labels starting at the start point specified using the increment specified. |
protected void |
fireStateChanged()
Send a ChangeEvent, whose source is this Slider, to each listener. |
ChangeListener[] |
getChangeListeners()
Returns an array of all the ChangeListener s added
to this JSlider with addChangeListener(). |
int |
getExtent()
Returns the "extent" -- the range of values "covered" by the knob. |
boolean |
getInverted()
Returns true if the value-range shown for the slider is reversed, |
java.util.Dictionary |
getLabelTable()
Returns the dictionary of what labels to draw at which values. |
int |
getMajorTickSpacing()
This method returns the major tick spacing. |
int |
getMaximum()
Returns the maximum value supported by the slider. |
int |
getMinimum()
Returns the minimum value supported by the slider. |
int |
getMinorTickSpacing()
This method returns the minor tick spacing. |
BoundedRangeModel |
getModel()
Returns data model that handles the sliders three fundamental properties: minimum, maximum, value. |
int |
getOrientation()
Return this slider's vertical or horizontal orientation. |
boolean |
getPaintLabels()
Tells if labels are to be painted. |
boolean |
getPaintTicks()
Tells if tick marks are to be painted. |
boolean |
getPaintTrack()
Tells if the track (area the slider slides in) is to be painted. |
boolean |
getSnapToTicks()
Returns true if the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob. |
int |
getValue()
Returns the sliders value. |
boolean |
getValueIsAdjusting()
True if the slider knob is being dragged. |
void |
paint(java.awt.Graphics g)
Invoked by Swing to draw components. |
protected void |
paintBorder(java.awt.Graphics g)
Paints the component's border. |
protected void |
paintComponent(java.awt.Graphics g)
Calls the UI delegate's paint method, if the UI delegate is non- null . |
void |
paintComponents(java.awt.Graphics g)
|
protected java.lang.String |
paramString()
Returns a string representation of this JSlider. |
protected void |
printBorder(java.awt.Graphics g)
Prints the component's border. |
protected void |
printComponent(java.awt.Graphics g)
This is invoked during a printing operation. |
void |
printComponents(java.awt.Graphics g)
|
void |
removeChangeListener(ChangeListener l)
Removes a ChangeListener from the slider. |
void |
setExtent(int extent)
Sets the size of the range "covered" by the knob. |
void |
setInverted(boolean b)
Specify true to reverse the value-range shown for the slider and false to put the value range in the normal order. |
void |
setLabelTable(java.util.Dictionary labels)
Used to specify what label will be drawn at any given value. |
void |
setMajorTickSpacing(int n)
This method sets the major tick spacing. |
void |
setMaximum(int maximum)
Sets the models maximum property. |
void |
setMinimum(int minimum)
Sets the models minimum property. |
void |
setMinorTickSpacing(int n)
This method sets the minor tick spacing. |
void |
setModel(BoundedRangeModel newModel)
Sets the model that handles the sliders three fundamental properties: minimum, maximum, value. |
void |
setOrientation(int orientation)
Set the scrollbars orientation to either VERTICAL or HORIZONTAL. |
void |
setPaintLabels(boolean b)
Determines whether labels are painted on the slider. |
void |
setPaintTicks(boolean b)
Determines whether tick marks are painted on the slider. |
void |
setPaintTrack(boolean b)
Determines whether the track is painted on the slider. |
void |
setSnapToTicks(boolean b)
Specifying true makes the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob. |
void |
setValue(int n)
Sets the sliders current value. |
void |
setValueIsAdjusting(boolean b)
Sets the models valueIsAdjusting property. |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, list, list, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getCursor, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getSize, getToolkit, getTreeLock, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, setBounds, setBounds, setCursor, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected BoundedRangeModel sliderModel
protected int majorTickSpacing
protected int minorTickSpacing
setMinorTickSpacing(int)
protected boolean snapToTicks
setSnapToTicks(boolean)
protected int orientation
setOrientation(int)
protected ChangeListener changeListener
addChangeListener(javax.swing.event.ChangeListener)
,
createChangeListener()
protected transient ChangeEvent changeEvent
ChangeEvent
is needed per slider instance since the
event's only (read-only) state is the source property. The source
of events generated here is always "this". The event is lazily
created the first time that an event notification is fired.
fireStateChanged()
Constructor Detail |
public JSlider()
public JSlider(int orientation)
public JSlider(int min, int max)
public JSlider(int min, int max, int value)
public JSlider(int orientation, int min, int max, int value)
java.lang.IllegalArgumentException
- if orientation is not one of VERTICAL, HORIZONTALsetOrientation(int)
,
setMinimum(int)
,
setMaximum(int)
,
setValue(int)
public JSlider(BoundedRangeModel brm)
Method Detail |
public final void paint(java.awt.Graphics g)
JComponent
paint
directly,
but should instead use the repaint
method to
schedule the component for redrawing.
This method actually delegates the work of painting to three
protected methods: paintComponent
,
paintBorder
,
and paintChildren
. They're called in the order
listed to ensure that children appear on top of component itself.
Generally speaking, the component and its children should not
paint in the insets area allocated to the border. Subclasses can
just override this method, as always.
paint
in class JComponent
g
- the Graphics
context in which to paintJComponent.paintBorder(java.awt.Graphics)
,
JComponent.paintChildren(java.awt.Graphics)
,
JComponent.getComponentGraphics(java.awt.Graphics)
,
JComponent.repaint(long, int, int, int, int)
protected ChangeListener createChangeListener()
fireStateChanged()
public void addChangeListener(ChangeListener l)
l
- the ChangeListener to addfireStateChanged()
,
removeChangeListener(javax.swing.event.ChangeListener)
public void removeChangeListener(ChangeListener l)
l
- the ChangeListener to removefireStateChanged()
,
addChangeListener(javax.swing.event.ChangeListener)
public ChangeListener[] getChangeListeners()
ChangeListener
s added
to this JSlider with addChangeListener().
ChangeListener
s added or an empty
array if no listeners have been addedprotected void fireStateChanged()
addChangeListener(javax.swing.event.ChangeListener)
,
EventListenerList
public BoundedRangeModel getModel()
setModel(javax.swing.BoundedRangeModel)
public void setModel(BoundedRangeModel newModel)
getModel()
public int getValue()
setValue(int)
public void setValue(int n)
getValue()
public int getMinimum()
setMinimum(int)
public void setMinimum(int minimum)
getMinimum()
,
BoundedRangeModel.setMinimum(int)
public int getMaximum()
setMaximum(int)
public void setMaximum(int maximum)
getMaximum()
,
BoundedRangeModel.setMaximum(int)
public boolean getValueIsAdjusting()
setValueIsAdjusting(boolean)
public void setValueIsAdjusting(boolean b)
getValueIsAdjusting()
,
BoundedRangeModel.setValueIsAdjusting(boolean)
public int getExtent()
setExtent(int)
,
BoundedRangeModel.getExtent()
public void setExtent(int extent)
getExtent()
,
BoundedRangeModel.setExtent(int)
public int getOrientation()
setOrientation(int)
public void setOrientation(int orientation)
java.lang.IllegalArgumentException
- if orientation is not one of VERTICAL, HORIZONTALgetOrientation()
public java.util.Dictionary getLabelTable()
Dictionary
containing labels and
where to draw thempublic void setLabelTable(java.util.Dictionary labels)
{ Integer value, java.swing.JComponent label }
.
createStandardLabels(int)
,
getLabelTable()
public java.util.Hashtable createStandardLabels(int increment)
createStandardLabels( 10 )
and the slider minimum is
zero, then it will make labels for the values 0, 10, 20, 30, and so on.
setLabelTable(java.util.Dictionary)
public java.util.Hashtable createStandardLabels(int increment, int start)
createStandardLabels( 10, 2 )
,
then it will make labels for the values 2, 12, 22, 32, and so on.
java.lang.IllegalArgumentException
- if slider label start point
out of range or if label increment is less than or equal
to zerosetLabelTable(java.util.Dictionary)
public boolean getInverted()
setInverted(boolean)
public void setInverted(boolean b)
b
- true to reverse the slider values from their normal orderpublic int getMajorTickSpacing()
setMajorTickSpacing(int)
public void setMajorTickSpacing(int n)
getMajorTickSpacing()
public int getMinorTickSpacing()
getMinorTickSpacing()
public void setMinorTickSpacing(int n)
getMinorTickSpacing()
public boolean getSnapToTicks()
setSnapToTicks(boolean)
public void setSnapToTicks(boolean b)
b
- true to snap the knob to the nearest tick markgetSnapToTicks()
public boolean getPaintTicks()
setPaintTicks(boolean)
public void setPaintTicks(boolean b)
getPaintTicks()
public boolean getPaintTrack()
setPaintTrack(boolean)
public void setPaintTrack(boolean b)
getPaintTrack()
public boolean getPaintLabels()
setPaintLabels(boolean)
public void setPaintLabels(boolean b)
getPaintLabels()
protected java.lang.String paramString()
null
.
paramString
in class JComponent
protected final void paintComponent(java.awt.Graphics g)
JComponent
null
. We pass the delegate a copy of the
Graphics
object to protect the rest of the
paint code from irrevocable changes
(for example, Graphics.translate
).
paintComponent
in class JComponent
g
- the Graphics
object to protectJComponent.paint(java.awt.Graphics)
,
ComponentUI
protected final void paintBorder(java.awt.Graphics g)
JComponent
paintBorder
in class JComponent
g
- the Graphics
context in which to paintJComponent.paint(java.awt.Graphics)
,
JComponent.setBorder(javax.swing.border.Border)
public final void paintComponents(java.awt.Graphics g)
protected final void printComponent(java.awt.Graphics g)
JComponent
paintComponent
on the component.
printComponent
in class JComponent
g
- the Graphics
context in which to paintJComponent.print(java.awt.Graphics)
protected final void printBorder(java.awt.Graphics g)
JComponent
paintBorder
on the component.
printBorder
in class JComponent
g
- the Graphics
context in which to paintJComponent.print(java.awt.Graphics)
public final void printComponents(java.awt.Graphics g)
|
JSR-209 (Final Release) | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |