javax.swing.plaf.basic

Class BasicSliderUI

public class BasicSliderUI extends SliderUI

BasicSliderUI.java This is the UI delegate in the Basic look and feel that paints JSliders.

The UI delegate keeps track of 6 rectangles that place the various parts of the JSlider inside the component.

The rectangles are organized as follows:

     +-------------------------------------------------------+ <-- focusRect
     |                                                       |
     |  +==+-------------------+==+--------------------+==+<------ contentRect
     |  |  |                   |  |<---thumbRect       |  |  |
     |  |  |    TRACK          |  |                    |<--------- trackRect
     |  |  +-------------------+==+--------------------+  |  |
     |  |  |                                           |  |  |
     |  |  |          TICKS GO HERE                    |<-------- tickRect
     |  |  |                                           |  |  |
     |  +==+-------------------------------------------+==+  |
     |  |  |                                           |  |  |
     |  |  |                                           |  |<----- labelRect
     |  |  |                 LABELS GO HERE            |  |  |
     |  |  |                                           |  |  |
     |  |  |                                           |  |  |
     |  |  |                                           |  |  |
     |  |  |                                           |  |  |
     |  |                                              |  |  |
 

The space between the contentRect and the focusRect are the FocusInsets.

The space between the focusRect and the component bounds is the insetCache which are the component's insets.

The top of the thumb is the top of the contentRect. The trackRect has to be as tall as the thumb.

The trackRect and tickRect do not start from the left edge of the focusRect. They are trackBuffer away from each side of the focusRect. This is so that the thumb has room to move.

The labelRect does start right against the contentRect's left and right edges and it gets all remaining space.

Nested Class Summary
classBasicSliderUI.ActionScroller
This class is no longer used as of JDK1.3.
classBasicSliderUI.ChangeHandler
Helper class that listens to the {@link JSlider}'s model for changes.
classBasicSliderUI.ComponentHandler
Helper class that listens for resize events.
classBasicSliderUI.FocusHandler
Helper class that listens for focus events.
classBasicSliderUI.PropertyChangeHandler
Helper class that listens for changes to the properties of the {@link JSlider}.
classBasicSliderUI.ScrollListener
Helper class that listens to our swing timer.
classBasicSliderUI.TrackListener
Helper class that listens for mouse events.
Field Summary
protected ChangeListenerchangeListener
Listener for changes from the model.
protected ComponentListenercomponentListener
Listener for component resizing.
protected RectanglecontentRect
Rectangle describing content bounds.
protected InsetsfocusInsets
The insets between the FocusRectangle and the ContentRectangle.
protected FocusListenerfocusListener
Listener for focus handling.
protected RectanglefocusRect
Rectangle describing focus bounds.
protected InsetsinsetCache
The {@link JSlider}'s insets.
protected RectanglelabelRect
Rectangle describing the label bounds.
protected booleanleftToRightCache
Whether this slider is actually drawn left to right.
static intMAX_SCROLL
FIXME: use this somewhere.
static intMIN_SCROLL
FIXME: use this somewhere.
static intNEGATIVE_SCROLL
A constant describing scrolling towards the minimum.
protected PropertyChangeListenerpropertyChangeListener
Listener for changes to the {@link JSlider}.
static intPOSITIVE_SCROLL
A constant describing scrolling towards the maximum.
protected BasicSliderUI.ScrollListenerscrollListener
Listener for the scrollTimer.
protected TimerscrollTimer
A timer that periodically moves the thumb.
protected JSliderslider
A reference to the {@link JSlider} that this UI was created for.
protected RectanglethumbRect
Rectangle describing the thumb's bounds.
protected RectangletickRect
Rectangle describing the tick bounds.
protected inttrackBuffer
The gap between the edges of the contentRect and trackRect.
protected BasicSliderUI.TrackListenertrackListener
Listener for mouse events.
protected RectangletrackRect
Rectangle describing the track bounds.
Constructor Summary
BasicSliderUI(JSlider b)
Creates a new Basic look and feel Slider UI.
Method Summary
protected voidcalculateContentRect()
Updates the contentRect field to an area inside the focusRect.
protected voidcalculateFocusRect()
This method calculates the size and position of the focusRect.
protected voidcalculateGeometry()
This method calculates all the sizes of the rectangles by delegating to the helper methods calculateXXXRect.
protected voidcalculateLabelRect()
Calculates the labelRect field, taking into account the orientation of the slider.
protected voidcalculateThumbLocation()
Calculates the position of the thumbRect based on the current value of the slider.
protected voidcalculateThumbSize()
Sets the width and height of the thumbRect field, using the dimensions returned by {@link #getThumbSize()}.
protected voidcalculateTickRect()
This method calculates the size and position of the tickRect.
protected voidcalculateTrackBuffer()
Calculates the gap size between the edge of the contentRect and the edge of the trackRect, storing the result in the trackBuffer field.
protected voidcalculateTrackRect()
Calculates the size and position of the trackRect.
protected ChangeListenercreateChangeListener(JSlider slider)
Creates a new {@link ChangeListener}.
protected ComponentListenercreateComponentListener(JSlider slider)
Creates a new {@link ComponentListener}.
protected FocusListenercreateFocusListener(JSlider slider)
Creates a new {@link FocusListener}.
protected PropertyChangeListenercreatePropertyChangeListener(JSlider slider)
Creates a new {@link PropertyChangeListener}.
protected BasicSliderUI.ScrollListenercreateScrollListener(JSlider slider)
Creates a new {@link ScrollListener}.
protected BasicSliderUI.TrackListenercreateTrackListener(JSlider slider)
Creates a new {@link TrackListener}.
static ComponentUIcreateUI(JComponent b)
Factory method to create a BasicSliderUI for the given {@link JComponent}, which should be a {@link JSlider}.
protected booleandrawInverted()
Returns true if the slider scale is to be drawn inverted, and false if not.
protected ColorgetFocusColor()
Gets the focus color to be used for this slider.
protected intgetHeightOfHighValueLabel()
Returns the height of the label whose key has the highest value, or 0 if there are no labels.
protected intgetHeightOfLowValueLabel()
Returns the height of the label whose key has the lowest value, or 0 if there are no labels.
protected intgetHeightOfTallestLabel()
This method returns the height of the tallest label in the slider's label table.
protected ComponentgetHighestValueLabel()
Returns the label whose key has the highest value.
protected ColorgetHighlightColor()
Gets the highlight color to be used for this slider.
protected ComponentgetLowestValueLabel()
This method returns the label whose key has the lowest value.
DimensiongetMaximumSize(JComponent c)
This method returns the maximum size for this {@link JSlider} for this look and feel.
DimensiongetMinimumHorizontalSize()
This method returns the minimum size when the slider is horizontally oriented.
DimensiongetMinimumSize(JComponent c)
This method returns the minimum size for this {@link JSlider} for this look and feel.
DimensiongetMinimumVerticalSize()
This method returns the minimum size of the slider when it is vertically oriented.
DimensiongetPreferredHorizontalSize()
This method returns the preferred size when the slider is horizontally oriented.
DimensiongetPreferredSize(JComponent c)
This method returns the preferred size of the component.
DimensiongetPreferredVerticalSize()
This method returns the preferred size when the slider is vertically oriented.
protected ColorgetShadowColor()
Gets the shadow color to be used for this slider.
protected DimensiongetThumbSize()
Returns the size of the slider's thumb.
protected intgetTickLength()
This method returns the height of the tick area box if the slider is horizontal and the width of the tick area box is the slider is vertical.
protected intgetWidthOfHighValueLabel()
Returns the width of the label whose key has the highest value, or 0 if there are no labels.
protected intgetWidthOfLowValueLabel()
Returns the width of the label whose key has the lowest value, or 0 if there are no labels.
protected intgetWidthOfWidestLabel()
This method returns the width of the widest label in the slider's label table.
protected voidinstallDefaults(JSlider slider)
Initializes any default properties that this UI has from the defaults for the Basic look and feel.
protected voidinstallKeyboardActions(JSlider slider)
Installs any keyboard actions.
protected voidinstallListeners(JSlider slider)
Creates and registers all the listeners for this UI delegate.
voidinstallUI(JComponent c)
Installs and initializes all fields for this UI delegate.
protected booleanisDragging()
Returns true if the user is dragging the slider.
voidpaint(Graphics g, JComponent c)
This method is used to paint the {@link JSlider}.
voidpaintFocus(Graphics g)
This method is called during a repaint if the slider has focus.
protected voidpaintHorizontalLabel(Graphics g, int value, Component label)
This method paints the label on the horizontal slider at the value specified.
voidpaintLabels(Graphics g)
This method paints all the labels from the slider's label table.
protected voidpaintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
This method paints a major tick for a horizontal slider at the given x value. x represents the x coordinate to paint at.
protected voidpaintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
This method paints a major tick for a vertical slider at the given y value. y represents the y coordinate to paint at.
protected voidpaintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
This method paints a minor tick for a horizontal slider at the given x value. x represents the x coordinate to paint at.
protected voidpaintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
This method paints a minor tick for a vertical slider at the given y value. y represents the y coordinate to paint at.
voidpaintThumb(Graphics g)

This method paints a thumb.

voidpaintTicks(Graphics g)
This method is called during a repaint if the ticks are to be drawn.
voidpaintTrack(Graphics g)

This method is called during a repaint if the track is to be drawn.

protected voidpaintVerticalLabel(Graphics g, int value, Component label)
This method paints the label on the vertical slider at the value specified.
protected voidrecalculateIfInsetsChanged()
This method recalculates any rectangles that need to be recalculated after the insets of the component have changed.
protected voidrecalculateIfOrientationChanged()
This method recalculates any rectangles that need to be recalculated after the orientation of the slider changes.
voidscrollByBlock(int direction)
Moves the thumb one block in the direction specified (a block is 1/10th of the slider range).
voidscrollByUnit(int direction)
Moves the thumb one unit in the specified direction.
protected voidscrollDueToClickInTrack(int dir)
This method is called when there has been a click in the track and the thumb needs to be scrolled on regular intervals.
voidsetThumbLocation(int x, int y)
This method sets the position of the thumbRect.
protected voiduninstallKeyboardActions(JSlider slider)
Uninstalls any keyboard actions.
protected voiduninstallListeners(JSlider slider)
Unregisters all the listeners that this UI delegate was using.
voiduninstallUI(JComponent c)
Performs the opposite of installUI.
intvalueForXPosition(int xPos)
This method returns the value in the slider's range given the x coordinate.
intvalueForYPosition(int yPos)
This method returns the value in the slider's range given the y coordinate.
protected intxPositionForValue(int value)
Returns the x-coordinate (relative to the component) for the given slider value.
protected intyPositionForValue(int value)
Returns the y-coordinate (relative to the component) for the given slider value.

Field Detail

changeListener

protected ChangeListener changeListener
Listener for changes from the model.

componentListener

protected ComponentListener componentListener
Listener for component resizing.

contentRect

protected Rectangle contentRect
Rectangle describing content bounds. See diagram above.

focusInsets

protected Insets focusInsets
The insets between the FocusRectangle and the ContentRectangle.

focusListener

protected FocusListener focusListener
Listener for focus handling.

focusRect

protected Rectangle focusRect
Rectangle describing focus bounds. See diagram above.

insetCache

protected Insets insetCache
The {@link JSlider}'s insets.

labelRect

protected Rectangle labelRect
Rectangle describing the label bounds. See diagram above.

leftToRightCache

protected boolean leftToRightCache
Whether this slider is actually drawn left to right.

MAX_SCROLL

public static final int MAX_SCROLL
FIXME: use this somewhere.

MIN_SCROLL

public static final int MIN_SCROLL
FIXME: use this somewhere.

NEGATIVE_SCROLL

public static final int NEGATIVE_SCROLL
A constant describing scrolling towards the minimum.

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
Listener for changes to the {@link JSlider}.

POSITIVE_SCROLL

public static final int POSITIVE_SCROLL
A constant describing scrolling towards the maximum.

scrollListener

protected BasicSliderUI.ScrollListener scrollListener
Listener for the scrollTimer.

scrollTimer

protected Timer scrollTimer
A timer that periodically moves the thumb.

slider

protected JSlider slider
A reference to the {@link JSlider} that this UI was created for.

thumbRect

protected Rectangle thumbRect
Rectangle describing the thumb's bounds. See diagram above.

tickRect

protected Rectangle tickRect
Rectangle describing the tick bounds. See diagram above.

trackBuffer

protected int trackBuffer
The gap between the edges of the contentRect and trackRect.

trackListener

protected BasicSliderUI.TrackListener trackListener
Listener for mouse events.

trackRect

protected Rectangle trackRect
Rectangle describing the track bounds. See diagram above.

Constructor Detail

BasicSliderUI

public BasicSliderUI(JSlider b)
Creates a new Basic look and feel Slider UI.

Parameters: b The {@link JSlider} that this UI was created for.

Method Detail

calculateContentRect

protected void calculateContentRect()
Updates the contentRect field to an area inside the focusRect. This method does not need to be called if the orientation changes.

calculateFocusRect

protected void calculateFocusRect()
This method calculates the size and position of the focusRect. This method does not need to be called if the orientation changes.

calculateGeometry

protected void calculateGeometry()
This method calculates all the sizes of the rectangles by delegating to the helper methods calculateXXXRect.

calculateLabelRect

protected void calculateLabelRect()
Calculates the labelRect field, taking into account the orientation of the slider.

calculateThumbLocation

protected void calculateThumbLocation()
Calculates the position of the thumbRect based on the current value of the slider. It must take into account the orientation of the slider.

calculateThumbSize

protected void calculateThumbSize()
Sets the width and height of the thumbRect field, using the dimensions returned by {@link #getThumbSize()}.

calculateTickRect

protected void calculateTickRect()
This method calculates the size and position of the tickRect. It must take into account the orientation of the slider.

calculateTrackBuffer

protected void calculateTrackBuffer()
Calculates the gap size between the edge of the contentRect and the edge of the trackRect, storing the result in the trackBuffer field. Sufficient space needs to be reserved for the slider thumb and/or the labels at each end of the slider track.

calculateTrackRect

protected void calculateTrackRect()
Calculates the size and position of the trackRect. It must take into account the orientation of the slider.

createChangeListener

protected ChangeListener createChangeListener(JSlider slider)
Creates a new {@link ChangeListener}.

Parameters: slider The {@link JSlider} that this {@link ChangeListener} is created for.

Returns: A new {@link ChangeListener}.

createComponentListener

protected ComponentListener createComponentListener(JSlider slider)
Creates a new {@link ComponentListener}.

Parameters: slider The {@link JSlider} that this {@link ComponentListener} is created for.

Returns: A new {@link ComponentListener}.

createFocusListener

protected FocusListener createFocusListener(JSlider slider)
Creates a new {@link FocusListener}.

Parameters: slider The {@link JSlider} that this {@link FocusListener} is created for.

Returns: A new {@link FocusListener}.

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener(JSlider slider)
Creates a new {@link PropertyChangeListener}.

Parameters: slider The {@link JSlider} that this {@link PropertyChangeListener} is created for.

Returns: A new {@link PropertyChangeListener}.

createScrollListener

protected BasicSliderUI.ScrollListener createScrollListener(JSlider slider)
Creates a new {@link ScrollListener}.

Parameters: slider The {@link JSlider} that this {@link ScrollListener} is created for.

Returns: A new {@link ScrollListener}.

createTrackListener

protected BasicSliderUI.TrackListener createTrackListener(JSlider slider)
Creates a new {@link TrackListener}.

Parameters: slider The {@link JSlider} that this {@link TrackListener} is created for.

Returns: A new {@link TrackListener}.

createUI

public static ComponentUI createUI(JComponent b)
Factory method to create a BasicSliderUI for the given {@link JComponent}, which should be a {@link JSlider}.

Parameters: b The {@link JComponent} a UI is being created for.

Returns: A BasicSliderUI for the {@link JComponent}.

drawInverted

protected boolean drawInverted()
Returns true if the slider scale is to be drawn inverted, and false if not.

Returns: true if the slider is to be drawn inverted.

getFocusColor

protected Color getFocusColor()
Gets the focus color to be used for this slider. The focus color is the color used for drawing the focus rectangle when the component gains focus.

Returns: The focus color.

getHeightOfHighValueLabel

protected int getHeightOfHighValueLabel()
Returns the height of the label whose key has the highest value, or 0 if there are no labels.

Returns: The height of the high value label or 0 if no label table exists.

getHeightOfLowValueLabel

protected int getHeightOfLowValueLabel()
Returns the height of the label whose key has the lowest value, or 0 if there are no labels.

Returns: The height of the low value label or 0 if no label table exists.

getHeightOfTallestLabel

protected int getHeightOfTallestLabel()
This method returns the height of the tallest label in the slider's label table.

Returns: The height of the tallest label or 0 if no label table exists.

getHighestValueLabel

protected Component getHighestValueLabel()
Returns the label whose key has the highest value.

Returns: The label whose key has the highest value or null if no label table exists.

getHighlightColor

protected Color getHighlightColor()
Gets the highlight color to be used for this slider. The highlight color is the color used for drawing the bottom and right edges of the track.

Returns: The highlight color.

getLowestValueLabel

protected Component getLowestValueLabel()
This method returns the label whose key has the lowest value.

Returns: The low value label or null if no label table exists.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size for this {@link JSlider} for this look and feel.

Parameters: c The {@link JComponent} to find a maximum size for.

Returns: The dimensions of the maximum size.

getMinimumHorizontalSize

public Dimension getMinimumHorizontalSize()
This method returns the minimum size when the slider is horizontally oriented.

Returns: The dimensions of the minimum horizontal size.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size for this {@link JSlider} for this look and feel. If it returns null, then it is up to the Layout Manager to give the {@link JComponent} a size.

Parameters: c The {@link JComponent} to find the minimum size for.

Returns: The dimensions of the minimum size.

getMinimumVerticalSize

public Dimension getMinimumVerticalSize()
This method returns the minimum size of the slider when it is vertically oriented.

Returns: The dimensions of the minimum vertical size.

getPreferredHorizontalSize

public Dimension getPreferredHorizontalSize()
This method returns the preferred size when the slider is horizontally oriented.

Returns: The dimensions of the preferred horizontal size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
This method returns the preferred size of the component. If it returns null, then it is up to the Layout Manager to give the {@link JComponent} a size.

Parameters: c The {@link JComponent} to find the preferred size for.

Returns: The dimensions of the preferred size.

getPreferredVerticalSize

public Dimension getPreferredVerticalSize()
This method returns the preferred size when the slider is vertically oriented.

Returns: The dimensions of the preferred vertical size.

getShadowColor

protected Color getShadowColor()
Gets the shadow color to be used for this slider. The shadow color is the color used for drawing the top and left edges of the track.

Returns: The shadow color.

getThumbSize

protected Dimension getThumbSize()
Returns the size of the slider's thumb. The size is hard coded to 11 x 20 for horizontal sliders, and 20 x 11 for vertical sliders. Note that a new instance of {@link Dimension} is returned for every call to this method (this seems wasteful, but {@link Dimension} instances are not immutable, so this is probably unavoidable).

Returns: The size of the slider's thumb.

getTickLength

protected int getTickLength()
This method returns the height of the tick area box if the slider is horizontal and the width of the tick area box is the slider is vertical. It not necessarily how long the ticks will be. If a gap between the edge of tick box and the actual tick is desired, then that will need to be handled in the tick painting methods.

Returns: The height (or width if the slider is vertical) of the tick rectangle.

getWidthOfHighValueLabel

protected int getWidthOfHighValueLabel()
Returns the width of the label whose key has the highest value, or 0 if there are no labels.

Returns: The width of the label whose key has the highest value.

See Also: getHighestValueLabel

getWidthOfLowValueLabel

protected int getWidthOfLowValueLabel()
Returns the width of the label whose key has the lowest value, or 0 if there are no labels.

Returns: The width of the label whose key has the lowest value.

See Also: getLowestValueLabel

getWidthOfWidestLabel

protected int getWidthOfWidestLabel()
This method returns the width of the widest label in the slider's label table.

Returns: The width of the widest label or 0 if no label table exists.

installDefaults

protected void installDefaults(JSlider slider)
Initializes any default properties that this UI has from the defaults for the Basic look and feel.

Parameters: slider The {@link JSlider} that is having this UI installed.

installKeyboardActions

protected void installKeyboardActions(JSlider slider)
Installs any keyboard actions. The list of keys that need to be bound are listed in Basic look and feel's defaults.

Parameters: slider The {@link JSlider} that is having keyboard actions installed.

installListeners

protected void installListeners(JSlider slider)
Creates and registers all the listeners for this UI delegate. This includes creating the ScrollListener and registering it to the timer.

Parameters: slider The {@link JSlider} is having listeners installed.

installUI

public void installUI(JComponent c)
Installs and initializes all fields for this UI delegate. Any properties of the UI that need to be initialized and/or set to defaults will be done now. It will also install any listeners necessary.

Parameters: c The {@link JComponent} that is having this UI installed.

isDragging

protected boolean isDragging()
Returns true if the user is dragging the slider.

Returns: true if the slider is being dragged.

Since: 1.5

paint

public void paint(Graphics g, JComponent c)
This method is used to paint the {@link JSlider}. It delegates all its duties to the various paint methods like paintTicks(), paintTrack(), paintThumb(), etc.

Parameters: g The {@link Graphics} object to paint with. c The {@link JComponent} that is being painted.

paintFocus

public void paintFocus(Graphics g)
This method is called during a repaint if the slider has focus. It draws an outline of the focusRect using the color returned by getFocusColor().

Parameters: g The {@link Graphics} object to draw with.

paintHorizontalLabel

protected void paintHorizontalLabel(Graphics g, int value, Component label)
This method paints the label on the horizontal slider at the value specified. The value is not a coordinate. It is a value within the range of the slider. If the value is not within the range of the slider, this method will do nothing. This method should not paint outside the boundaries of the labelRect.

Parameters: g The {@link Graphics} object to draw with. value The value to paint at. label The label to paint.

paintLabels

public void paintLabels(Graphics g)
This method paints all the labels from the slider's label table. This method must make sure that the label table is not null before painting the labels. Each entry in the label table is a (integer, component) pair. Every label is painted at the value of the integer.

Parameters: g The {@link Graphics} object to draw with.

paintMajorTickForHorizSlider

protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
This method paints a major tick for a horizontal slider at the given x value. x represents the x coordinate to paint at.

Parameters: g The {@link Graphics} object to draw with. tickBounds The tickRect rectangle. x The x coordinate to draw the tick at.

paintMajorTickForVertSlider

protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
This method paints a major tick for a vertical slider at the given y value. y represents the y coordinate to paint at.

Parameters: g The {@link Graphics} object to draw with. tickBounds The tickRect rectangle. y The y coordinate to draw the tick at.

paintMinorTickForHorizSlider

protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
This method paints a minor tick for a horizontal slider at the given x value. x represents the x coordinate to paint at.

Parameters: g The {@link Graphics} object to draw with. tickBounds The tickRect rectangle. x The x coordinate to draw the tick at.

paintMinorTickForVertSlider

protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
This method paints a minor tick for a vertical slider at the given y value. y represents the y coordinate to paint at.

Parameters: g The {@link Graphics} object to draw with. tickBounds The tickRect rectangle. y The y coordinate to draw the tick at.

paintThumb

public void paintThumb(Graphics g)

This method paints a thumb. There are two types of thumb:

   Vertical         Horizontal
    a---b            a-----b
    |   |            |      \
    e   c            |       c
     \ /             |      /
      d              e-----d
  

In the case of vertical thumbs, we highlight the path b-a-e-d and shadow the path b-c-d. In the case of horizontal thumbs, we highlight the path c-b-a-e and shadow the path c-d-e. In both cases we fill the path a-b-c-d-e before shadows and highlights are drawn.

Parameters: g The graphics object to paint with

paintTicks

public void paintTicks(Graphics g)
This method is called during a repaint if the ticks are to be drawn. This method must still verify that the majorTickSpacing and minorTickSpacing are greater than zero before drawing the ticks.

Parameters: g The {@link Graphics} object to draw with.

paintTrack

public void paintTrack(Graphics g)

This method is called during a repaint if the track is to be drawn. It draws a 3D rectangle to represent the track. The track is not the size of the trackRect. The top and left edges of the track should be outlined with the shadow color. The bottom and right edges should be outlined with the highlight color.

    a---d   
    |   |   
    |   |   a------------------------d
    |   |   |                        |
    |   |   b------------------------c
    |   |
    |   |   
    b---c
 

The b-a-d path needs to be drawn with the shadow color and the b-c-d path needs to be drawn with the highlight color.

Parameters: g The {@link Graphics} object to draw with.

paintVerticalLabel

protected void paintVerticalLabel(Graphics g, int value, Component label)
This method paints the label on the vertical slider at the value specified. The value is not a coordinate. It is a value within the range of the slider. If the value is not within the range of the slider, this method will do nothing. This method should not paint outside the boundaries of the labelRect.

Parameters: g The {@link Graphics} object to draw with. value The value to paint at. label The label to paint.

recalculateIfInsetsChanged

protected void recalculateIfInsetsChanged()
This method recalculates any rectangles that need to be recalculated after the insets of the component have changed.

recalculateIfOrientationChanged

protected void recalculateIfOrientationChanged()
This method recalculates any rectangles that need to be recalculated after the orientation of the slider changes.

scrollByBlock

public void scrollByBlock(int direction)
Moves the thumb one block in the direction specified (a block is 1/10th of the slider range). If the slider snaps to ticks, this method is responsible for snapping it to a tick after the thumb has been moved.

Parameters: direction the direction (positive values increment the thumb position by one block, zero/negative values decrement the thumb position by one block).

scrollByUnit

public void scrollByUnit(int direction)
Moves the thumb one unit in the specified direction. If the slider snaps to ticks, this method is responsible for snapping it to a tick after the thumb has been moved.

Parameters: direction the direction (positive values increment the thumb position by one, zero/negative values decrement the thumb position by one).

scrollDueToClickInTrack

protected void scrollDueToClickInTrack(int dir)
This method is called when there has been a click in the track and the thumb needs to be scrolled on regular intervals. This method is only responsible for starting the timer and not for stopping it.

Parameters: dir The direction to move in.

setThumbLocation

public void setThumbLocation(int x, int y)
This method sets the position of the thumbRect.

Parameters: x The new x position. y The new y position.

uninstallKeyboardActions

protected void uninstallKeyboardActions(JSlider slider)
Uninstalls any keyboard actions. The list of keys used are listed in Basic look and feel's defaults.

Parameters: slider The {@link JSlider} that is having keyboard actions uninstalled.

uninstallListeners

protected void uninstallListeners(JSlider slider)
Unregisters all the listeners that this UI delegate was using. In addition, it will also null any listeners that it was using.

Parameters: slider The {@link JSlider} that is having listeners removed.

uninstallUI

public void uninstallUI(JComponent c)
Performs the opposite of installUI. Any properties or resources that need to be cleaned up will be done now. It will also uninstall any listeners it has. In addition, any properties of this UI will be nulled.

Parameters: c The {@link JComponent} that is having this UI uninstalled.

valueForXPosition

public int valueForXPosition(int xPos)
This method returns the value in the slider's range given the x coordinate. If the value is out of range, it will return the closest legal value.

Parameters: xPos The x coordinate to calculate a value for.

Returns: The value for the x coordinate.

valueForYPosition

public int valueForYPosition(int yPos)
This method returns the value in the slider's range given the y coordinate. If the value is out of range, it will return the closest legal value.

Parameters: yPos The y coordinate to calculate a value for.

Returns: The value for the y coordinate.

xPositionForValue

protected int xPositionForValue(int value)
Returns the x-coordinate (relative to the component) for the given slider value. This method assumes that the trackRect field is set up.

Parameters: value the slider value.

Returns: The x-coordinate.

yPositionForValue

protected int yPositionForValue(int value)
Returns the y-coordinate (relative to the component) for the given slider value. This method assumes that the trackRect field is set up.

Parameters: value the slider value.

Returns: The y-coordinate.