|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JSlider
Safe: 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.
For the keyboard keys used by this component in the standard Look and
Feel (L&F) renditions, see the
JSlider
key assignments.
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. |
private boolean |
isInverted
|
private Dictionary |
labelTable
|
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
|
private boolean |
paintLabels
|
private boolean |
paintTicks
|
private boolean |
paintTrack
|
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. |
(package private) boolean |
snapToValue
If true, the knob (and the data value it represents) resolve to the closest slider value next to where the user positioned the knob. |
private static String |
uiClassID
|
Fields inherited from class javax.swing.JComponent |
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Container |
|
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 |
Constructor Summary | |
JSlider()
Enabled: Creates a horizontal slider with the range 0 to 100 and an initial value of 50. |
|
JSlider(BoundedRangeModel brm)
Enabled: Creates a horizontal slider using the specified BoundedRangeModel. |
|
JSlider(int orientation)
Enabled: Creates a slider using the specified orientation with the range 0 to 100 and an initial value of 50. |
|
JSlider(int min,
int max)
Enabled: 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)
Enabled: Creates a horizontal slider using the specified min, max and value. |
|
JSlider(int orientation,
int min,
int max,
int value)
Enabled: Creates a slider with the specified orientation and the specified minimum, maximum, and initial values. |
Method Summary | |
void |
addChangeListener(ChangeListener l)
Enabled: Adds a ChangeListener to the slider. |
private void |
checkOrientation(int orientation)
|
protected ChangeListener |
createChangeListener()
Subclasses that want to handle model ChangeEvents differently can override this method to return their own ChangeListener implementation. |
Hashtable |
createStandardLabels(int increment)
Enabled: Creates a hashtable that will draw text labels starting at the slider minimum using the increment specified. |
Hashtable |
createStandardLabels(int increment,
int start)
Enabled: 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. |
AccessibleContext |
getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this JSlider. |
ChangeListener[] |
getChangeListeners()
Suppressed: Returns an array of all the ChangeListener s added
to this JSlider with addChangeListener(). |
int |
getExtent()
Enabled: Returns the "extent" -- the range of values "covered" by the knob. |
boolean |
getInverted()
Enabled: Returns true if the value-range shown for the slider is reversed, |
Dictionary |
getLabelTable()
Enabled: Returns the dictionary of what labels to draw at which values. |
int |
getMajorTickSpacing()
Enabled: This method returns the major tick spacing. |
int |
getMaximum()
Enabled: Returns the maximum value supported by the slider. |
int |
getMinimum()
Enabled: Returns the minimum value supported by the slider. |
int |
getMinorTickSpacing()
Enabled: This method returns the minor tick spacing. |
BoundedRangeModel |
getModel()
Enabled: Returns data model that handles the sliders three fundamental properties: minimum, maximum, value. |
int |
getOrientation()
Enabled: Return this slider's vertical or horizontal orientation. |
boolean |
getPaintLabels()
Enabled: Tells if labels are to be painted. |
boolean |
getPaintTicks()
Enabled: Tells if tick marks are to be painted. |
boolean |
getPaintTrack()
Enabled: Tells if the track (area the slider slides in) is to be painted. |
boolean |
getSnapToTicks()
Enabled: 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. |
(package private) boolean |
getSnapToValue()
Returns true if the knob (and the data value it represents) resolve to the closest slider value next to where the user positioned the knob. |
javax.swing.plaf.SliderUI |
getUI()
Suppressed: Gets the UI object which implements the L&F for this component. |
String |
getUIClassID()
Suppressed: Returns the name of the L&F class that renders this component. |
int |
getValue()
Enabled: Returns the sliders value. |
boolean |
getValueIsAdjusting()
Enabled: True if the slider knob is being dragged. |
protected String |
paramString()
Returns a string representation of this JSlider. |
void |
removeChangeListener(ChangeListener l)
Enabled: Removes a ChangeListener from the slider. |
void |
setExtent(int extent)
Enabled: Sets the size of the range "covered" by the knob. |
void |
setInverted(boolean b)
Enabled: Specify true to reverse the value-range shown for the slider and false to put the value range in the normal order. |
void |
setLabelTable(Dictionary labels)
Enabled: Used to specify what label will be drawn at any given value. |
void |
setMajorTickSpacing(int n)
Enabled: This method sets the major tick spacing. |
void |
setMaximum(int maximum)
Enabled: Sets the models maximum property. |
void |
setMinimum(int minimum)
Enabled: Sets the models minimum property. |
void |
setMinorTickSpacing(int n)
Enabled: This method sets the minor tick spacing. |
void |
setModel(BoundedRangeModel newModel)
Enabled: Sets the model that handles the sliders three fundamental properties: minimum, maximum, value. |
void |
setOrientation(int orientation)
Enabled: Set the scrollbars orientation to either VERTICAL or HORIZONTAL. |
void |
setPaintLabels(boolean b)
Enabled: Determines whether labels are painted on the slider. |
void |
setPaintTicks(boolean b)
Enabled: Determines whether tick marks are painted on the slider. |
void |
setPaintTrack(boolean b)
Enabled: Determines whether the track is painted on the slider. |
void |
setSnapToTicks(boolean b)
Enabled: 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. |
(package private) void |
setSnapToValue(boolean b)
Specifying true makes the knob (and the data value it represents) resolve to the closest slider value next to where the user positioned the knob. |
void |
setUI(javax.swing.plaf.SliderUI ui)
Suppressed: Sets the UI object which implements the L&F for this component. |
void |
setValue(int n)
Enabled: Sets the sliders current value. |
void |
setValueIsAdjusting(boolean b)
Enabled: Sets the models valueIsAdjusting property. |
protected void |
updateLabelUIs()
Resets the UI property to a value from the current look and feel. |
void |
updateUI()
Suppressed: Resets the UI property to a value from the current look and feel. |
private void |
writeObject(ObjectOutputStream s)
See readObject() and writeObject() in JComponent for more information about serialization in Swing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final String uiClassID
getUIClassID()
,
JComponent.readObject(java.io.ObjectInputStream)
private boolean paintTicks
private boolean paintTrack
private boolean paintLabels
private boolean isInverted
protected BoundedRangeModel sliderModel
protected int majorTickSpacing
protected int minorTickSpacing
setMinorTickSpacing(int)
protected boolean snapToTicks
setSnapToTicks(boolean)
boolean snapToValue
protected int orientation
setOrientation(int)
private Dictionary labelTable
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)
setOrientation(int)
,
setMinimum(int)
,
setMaximum(int)
,
setValue(int)
public JSlider(BoundedRangeModel brm)
Method Detail |
private void checkOrientation(int orientation)
public javax.swing.plaf.SliderUI getUI()
public void setUI(javax.swing.plaf.SliderUI ui)
ui
- the SliderUI L&F objectUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
updateUI
in class JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
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)
getOrientation()
public Dictionary getLabelTable()
Dictionary
containing labels and
where to draw thempublic void setLabelTable(Dictionary labels)
{ Integer value, java.swing.JComponent label }
.
createStandardLabels(int)
,
getLabelTable()
protected void updateLabelUIs()
JComponent.updateUI()
public 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 Hashtable createStandardLabels(int increment, int start)
createStandardLabels( 10, 2 )
,
then it will make labels for the values 2, 12, 22, 32, and so on.
setLabelTable(java.util.Dictionary)
public boolean getInverted()
setInverted(boolean)
public void setInverted(boolean b)
ComponentOrientation
property. Normal (non-inverted)
horizontal sliders with a ComponentOrientation
value of
LEFT_TO_RIGHT
have their maximum on the right.
Normal horizontal sliders with a ComponentOrientation
value of
RIGHT_TO_LEFT
have their maximum on the left. Normal vertical
sliders have their maximum on the top. These labels are reversed when the
slider is inverted.
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)
boolean getSnapToValue()
public void setSnapToTicks(boolean b)
b
- true to snap the knob to the nearest tick markgetSnapToTicks()
void setSnapToValue(boolean b)
b
- true to snap the knob to the nearest slider valuegetSnapToValue()
,
setSnapToTicks(boolean)
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()
private void writeObject(ObjectOutputStream s) throws IOException
s
- the ObjectOutputStream
in which to write
IOException
protected String paramString()
null
.
paramString
in class JComponent
public AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |