- java.lang.Object
- 
- javax.swing.plaf.ComponentUI
- 
- javax.swing.plaf.SliderUI
- 
- javax.swing.plaf.basic.BasicSliderUI
 
 
 
- 
- Direct Known Subclasses:
- MetalSliderUI,- SynthSliderUI
 
 public class BasicSliderUI extends SliderUI A Basic L&F implementation of SliderUI.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classBasicSliderUI.ActionScrollerAs of Java 2 platform v1.3 this undocumented class is no longer used.classBasicSliderUI.ChangeHandlerData model listener.classBasicSliderUI.ComponentHandlerListener for resizing events.classBasicSliderUI.FocusHandlerFocus-change listener.classBasicSliderUI.PropertyChangeHandlerA property change handler.classBasicSliderUI.ScrollListenerScroll-event listener.classBasicSliderUI.TrackListenerTrack mouse movements.
 - 
Field SummaryFields Modifier and Type Field Description protected ChangeListenerchangeListenerChange listenerprotected ComponentListenercomponentListenerComponent listenerprotected RectanglecontentRectContent rectangleprotected InsetsfocusInsetsFocus insetsprotected FocusListenerfocusListenerFocus listenerprotected RectanglefocusRectFocus rectangleprotected InsetsinsetCacheInset cacheprotected RectanglelabelRectLabel rectangleprotected booleanleftToRightCacheLeft-to-right cachestatic intMAX_SCROLLMaximum scrollstatic intMIN_SCROLLMinimum scrollstatic intNEGATIVE_SCROLLNegative scrollstatic intPOSITIVE_SCROLLPositive scrollprotected PropertyChangeListenerpropertyChangeListenerProperty chane listenerprotected BasicSliderUI.ScrollListenerscrollListenerScroll listenerprotected TimerscrollTimerScroll timerprotected JSlidersliderSliderprotected RectanglethumbRectThumb rectangleprotected RectangletickRectTick rectangleprotected inttrackBufferThe distance that the track is from the side of the controlprotected BasicSliderUI.TrackListenertrackListenerTrack listenerprotected RectangletrackRectTrack rectangle
 - 
Constructor SummaryConstructors Constructor Description BasicSliderUI(JSlider b)Constructs aBasicSliderUI.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcalculateContentRect()Calculates the content rectangle.protected voidcalculateFocusRect()Calculates the focus rectangle.protected voidcalculateGeometry()Calculates the geometry.protected voidcalculateLabelRect()Calculates the label rectangle.protected voidcalculateThumbLocation()Calculates the thumb location.protected voidcalculateThumbSize()Calculates the thumb size rectangle.protected voidcalculateTickRect()Calculates the tick rectangle.protected voidcalculateTrackBuffer()Calculates the track buffer.protected voidcalculateTrackRect()Calculates the track rectangle.protected ChangeListenercreateChangeListener(JSlider slider)Creates a change listener.protected ComponentListenercreateComponentListener(JSlider slider)Creates a composite listener.protected FocusListenercreateFocusListener(JSlider slider)Creates a focus listener.protected PropertyChangeListenercreatePropertyChangeListener(JSlider slider)Creates a property change listener.protected BasicSliderUI.ScrollListenercreateScrollListener(JSlider slider)Creates a scroll listener.protected BasicSliderUI.TrackListenercreateTrackListener(JSlider slider)Creates a track listener.static ComponentUIcreateUI(JComponent b)Creates a UI.protected booleandrawInverted()Draws inverted.intgetBaseline(JComponent c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)Returns an enum indicating how the baseline of the component changes as the size changes.protected ColorgetFocusColor()Returns the focus color.protected intgetHeightOfHighValueLabel()Returns the height of the highest value label.protected intgetHeightOfLowValueLabel()Returns the height of the lowest value label.protected intgetHeightOfTallestLabel()Returns the height of the tallest label.protected IntegergetHighestValue()Returns the biggest value that has an entry in the label table.protected ComponentgetHighestValueLabel()Returns the label that corresponds to the lowest slider value in the label table.protected ColorgetHighlightColor()Returns the highlight color.protected IntegergetLowestValue()Returns the smallest value that has an entry in the label table.protected ComponentgetLowestValueLabel()Returns the label that corresponds to the highest slider value in the label table.DimensiongetMaximumSize(JComponent c)Returns the maximum size.DimensiongetMinimumHorizontalSize()Returns the minimum horizontal size.DimensiongetMinimumSize(JComponent c)Returns the minimum size.DimensiongetMinimumVerticalSize()Returns the minimum vertical size.DimensiongetPreferredHorizontalSize()Returns the preferred horizontal size.DimensiongetPreferredSize(JComponent c)Returns the preferred size.DimensiongetPreferredVerticalSize()Returns the preferred vertical size.protected ColorgetShadowColor()Returns the shadow color.protected DimensiongetThumbSize()Returns the thumb size.protected intgetTickLength()Gets the height of the tick area for horizontal sliders and the width of the tick area for vertical sliders.protected intgetWidthOfHighValueLabel()Returns the width of the highest value label.protected intgetWidthOfLowValueLabel()Returns the width of the lowest value label.protected intgetWidthOfWidestLabel()Returns the width of the widest label.protected voidinstallDefaults(JSlider slider)Installs the defaults.protected voidinstallKeyboardActions(JSlider slider)Installs keyboard actions.protected voidinstallListeners(JSlider slider)Installs listeners.voidinstallUI(JComponent c)Installs a UI.protected booleanisDragging()Returns true if the user is dragging the slider.protected booleanlabelsHaveSameBaselines()Returns true if all the labels from the label table have the same baseline.voidpaintFocus(Graphics g)Paints focus.protected voidpaintHorizontalLabel(Graphics g, int value, Component label)Called for every label in the label table.voidpaintLabels(Graphics g)Paints the labels.protected voidpaintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)Paints major tick for horizontal slider.protected voidpaintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)Paints major tick for vertical slider.protected voidpaintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)Paints minor tick for horizontal slider.protected voidpaintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)Paints minor tick for vertical slider.voidpaintThumb(Graphics g)Paints the thumb.voidpaintTicks(Graphics g)Paints ticks.voidpaintTrack(Graphics g)Paints track.protected voidpaintVerticalLabel(Graphics g, int value, Component label)Called for every label in the label table.protected voidrecalculateIfInsetsChanged()Recalculates if the insets have changed.protected voidrecalculateIfOrientationChanged()Recalculates if the orientation has changed.voidscrollByBlock(int direction)Scrolls by block.voidscrollByUnit(int direction)Scrolls by unit.protected voidscrollDueToClickInTrack(int dir)This function is called when a mousePressed was detected in the track, not in the thumb.voidsetThumbLocation(int x, int y)Sets the thumb location.protected voiduninstallDefaults(JSlider slider)Uninstalls the defaults.protected voiduninstallKeyboardActions(JSlider slider)Uninstalls keyboard actions.protected voiduninstallListeners(JSlider slider)Uninstalls listeners.voiduninstallUI(JComponent c)Uninstalls a UI.intvalueForXPosition(int xPos)Returns the value at the x position.intvalueForYPosition(int yPos)Returns the value at the y position.protected intxPositionForValue(int value)Returns the x position for a value.protected intyPositionForValue(int value)Returns the y position for a value.protected intyPositionForValue(int value, int trackY, int trackHeight)Returns the y location for the specified value.- 
Methods declared in class javax.swing.plaf.ComponentUIcontains, getAccessibleChild, getAccessibleChildrenCount, paint, update
 
- 
 
- 
- 
- 
Field Detail- 
POSITIVE_SCROLLpublic static final int POSITIVE_SCROLL Positive scroll- See Also:
- Constant Field Values
 
 - 
NEGATIVE_SCROLLpublic static final int NEGATIVE_SCROLL Negative scroll- See Also:
- Constant Field Values
 
 - 
MIN_SCROLLpublic static final int MIN_SCROLL Minimum scroll- See Also:
- Constant Field Values
 
 - 
MAX_SCROLLpublic static final int MAX_SCROLL Maximum scroll- See Also:
- Constant Field Values
 
 - 
scrollTimerprotected Timer scrollTimer Scroll timer
 - 
sliderprotected JSlider slider Slider
 - 
focusInsetsprotected Insets focusInsets Focus insets
 - 
insetCacheprotected Insets insetCache Inset cache
 - 
leftToRightCacheprotected boolean leftToRightCache Left-to-right cache
 - 
focusRectprotected Rectangle focusRect Focus rectangle
 - 
contentRectprotected Rectangle contentRect Content rectangle
 - 
labelRectprotected Rectangle labelRect Label rectangle
 - 
tickRectprotected Rectangle tickRect Tick rectangle
 - 
trackRectprotected Rectangle trackRect Track rectangle
 - 
thumbRectprotected Rectangle thumbRect Thumb rectangle
 - 
trackBufferprotected int trackBuffer The distance that the track is from the side of the control
 - 
trackListenerprotected BasicSliderUI.TrackListener trackListener Track listener
 - 
changeListenerprotected ChangeListener changeListener Change listener
 - 
componentListenerprotected ComponentListener componentListener Component listener
 - 
focusListenerprotected FocusListener focusListener Focus listener
 - 
scrollListenerprotected BasicSliderUI.ScrollListener scrollListener Scroll listener
 - 
propertyChangeListenerprotected PropertyChangeListener propertyChangeListener Property chane listener
 
- 
 - 
Constructor Detail- 
BasicSliderUIpublic BasicSliderUI(JSlider b) Constructs aBasicSliderUI.- Parameters:
- b- a slider
 
 
- 
 - 
Method Detail- 
getShadowColorprotected Color getShadowColor() Returns the shadow color.- Returns:
- the shadow color
 
 - 
getHighlightColorprotected Color getHighlightColor() Returns the highlight color.- Returns:
- the highlight color
 
 - 
getFocusColorprotected Color getFocusColor() Returns the focus color.- Returns:
- the focus color
 
 - 
isDraggingprotected boolean isDragging() Returns true if the user is dragging the slider.- Returns:
- true if the user is dragging the slider
- Since:
- 1.5
 
 - 
createUIpublic static ComponentUI createUI(JComponent b) Creates a UI.- Parameters:
- b- a component
- Returns:
- a UI
 
 - 
installUIpublic void installUI(JComponent c) Installs a UI.- Overrides:
- installUIin class- ComponentUI
- Parameters:
- c- a component
- See Also:
- ComponentUI.uninstallUI(javax.swing.JComponent),- JComponent.setUI(javax.swing.plaf.ComponentUI),- JComponent.updateUI()
 
 - 
uninstallUIpublic void uninstallUI(JComponent c) Uninstalls a UI.- Overrides:
- uninstallUIin class- ComponentUI
- Parameters:
- c- a component
- See Also:
- ComponentUI.installUI(javax.swing.JComponent),- JComponent.updateUI()
 
 - 
installDefaultsprotected void installDefaults(JSlider slider) Installs the defaults.- Parameters:
- slider- a slider
 
 - 
uninstallDefaultsprotected void uninstallDefaults(JSlider slider) Uninstalls the defaults.- Parameters:
- slider- a slider
 
 - 
createTrackListenerprotected BasicSliderUI.TrackListener createTrackListener(JSlider slider) Creates a track listener.- Parameters:
- slider- a slider
- Returns:
- a track listener
 
 - 
createChangeListenerprotected ChangeListener createChangeListener(JSlider slider) Creates a change listener.- Parameters:
- slider- a slider
- Returns:
- a change listener
 
 - 
createComponentListenerprotected ComponentListener createComponentListener(JSlider slider) Creates a composite listener.- Parameters:
- slider- a slider
- Returns:
- a composite listener
 
 - 
createFocusListenerprotected FocusListener createFocusListener(JSlider slider) Creates a focus listener.- Parameters:
- slider- a slider
- Returns:
- a focus listener
 
 - 
createScrollListenerprotected BasicSliderUI.ScrollListener createScrollListener(JSlider slider) Creates a scroll listener.- Parameters:
- slider- a slider
- Returns:
- a scroll listener
 
 - 
createPropertyChangeListenerprotected PropertyChangeListener createPropertyChangeListener(JSlider slider) Creates a property change listener.- Parameters:
- slider- a slider
- Returns:
- a property change listener
 
 - 
installListenersprotected void installListeners(JSlider slider) Installs listeners.- Parameters:
- slider- a slider
 
 - 
uninstallListenersprotected void uninstallListeners(JSlider slider) Uninstalls listeners.- Parameters:
- slider- a slider
 
 - 
installKeyboardActionsprotected void installKeyboardActions(JSlider slider) Installs keyboard actions.- Parameters:
- slider- a slider
 
 - 
uninstallKeyboardActionsprotected void uninstallKeyboardActions(JSlider slider) Uninstalls keyboard actions.- Parameters:
- slider- a slider
 
 - 
getBaselinepublic int getBaseline(JComponent c, int width, int height) Returns the baseline.- Overrides:
- getBaselinein class- ComponentUI
- Parameters:
- c-- JComponentbaseline is being requested for
- width- the width to get the baseline for
- height- the height to get the baseline for
- Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
- NullPointerException- if- cis- null
- IllegalArgumentException- if width or height is < 0
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
 - 
getBaselineResizeBehaviorpublic Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) Returns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
- getBaselineResizeBehaviorin class- ComponentUI
- Parameters:
- c-- JComponentto return baseline resize behavior for
- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
- NullPointerException- if- cis- null
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
 - 
labelsHaveSameBaselinesprotected boolean labelsHaveSameBaselines() Returns true if all the labels from the label table have the same baseline.- Returns:
- true if all the labels from the label table have the same baseline
- Since:
- 1.6
 
 - 
getPreferredHorizontalSizepublic Dimension getPreferredHorizontalSize() Returns the preferred horizontal size.- Returns:
- the preferred horizontal size
 
 - 
getPreferredVerticalSizepublic Dimension getPreferredVerticalSize() Returns the preferred vertical size.- Returns:
- the preferred vertical size
 
 - 
getMinimumHorizontalSizepublic Dimension getMinimumHorizontalSize() Returns the minimum horizontal size.- Returns:
- the minimum horizontal size
 
 - 
getMinimumVerticalSizepublic Dimension getMinimumVerticalSize() Returns the minimum vertical size.- Returns:
- the minimum vertical size
 
 - 
getPreferredSizepublic Dimension getPreferredSize(JComponent c) Returns the preferred size.- Overrides:
- getPreferredSizein class- ComponentUI
- Parameters:
- c- a component
- Returns:
- the preferred size
- See Also:
- JComponent.getPreferredSize(),- LayoutManager.preferredLayoutSize(java.awt.Container)
 
 - 
getMinimumSizepublic Dimension getMinimumSize(JComponent c) Returns the minimum size.- Overrides:
- getMinimumSizein class- ComponentUI
- Parameters:
- c- a component
- Returns:
- the minimum size
- See Also:
- JComponent.getMinimumSize(),- LayoutManager.minimumLayoutSize(java.awt.Container),- ComponentUI.getPreferredSize(javax.swing.JComponent)
 
 - 
getMaximumSizepublic Dimension getMaximumSize(JComponent c) Returns the maximum size.- Overrides:
- getMaximumSizein class- ComponentUI
- Parameters:
- c- a component
- Returns:
- the maximum size
- See Also:
- JComponent.getMaximumSize(),- LayoutManager2.maximumLayoutSize(java.awt.Container)
 
 - 
calculateGeometryprotected void calculateGeometry() Calculates the geometry.
 - 
calculateFocusRectprotected void calculateFocusRect() Calculates the focus rectangle.
 - 
calculateThumbSizeprotected void calculateThumbSize() Calculates the thumb size rectangle.
 - 
calculateContentRectprotected void calculateContentRect() Calculates the content rectangle.
 - 
calculateThumbLocationprotected void calculateThumbLocation() Calculates the thumb location.
 - 
calculateTrackBufferprotected void calculateTrackBuffer() Calculates the track buffer.
 - 
calculateTrackRectprotected void calculateTrackRect() Calculates the track rectangle.
 - 
getTickLengthprotected int getTickLength() Gets the height of the tick area for horizontal sliders and the width of the tick area for vertical sliders. BasicSliderUI uses the returned value to determine the tick area rectangle. If you want to give your ticks some room, make this larger than you need and paint your ticks away from the sides in paintTicks().- Returns:
- an integer representing the height of the tick area for horizontal sliders, and the width of the tick area for the vertical sliders
 
 - 
calculateTickRectprotected void calculateTickRect() Calculates the tick rectangle.
 - 
calculateLabelRectprotected void calculateLabelRect() Calculates the label rectangle.
 - 
getThumbSizeprotected Dimension getThumbSize() Returns the thumb size.- Returns:
- the thumb size
 
 - 
getWidthOfWidestLabelprotected int getWidthOfWidestLabel() Returns the width of the widest label.- Returns:
- the width of the widest label
 
 - 
getHeightOfTallestLabelprotected int getHeightOfTallestLabel() Returns the height of the tallest label.- Returns:
- the height of the tallest label
 
 - 
getWidthOfHighValueLabelprotected int getWidthOfHighValueLabel() Returns the width of the highest value label.- Returns:
- the width of the highest value label
 
 - 
getWidthOfLowValueLabelprotected int getWidthOfLowValueLabel() Returns the width of the lowest value label.- Returns:
- the width of the lowest value label
 
 - 
getHeightOfHighValueLabelprotected int getHeightOfHighValueLabel() Returns the height of the highest value label.- Returns:
- the height of the highest value label
 
 - 
getHeightOfLowValueLabelprotected int getHeightOfLowValueLabel() Returns the height of the lowest value label.- Returns:
- the height of the lowest value label
 
 - 
drawInvertedprotected boolean drawInverted() Draws inverted.- Returns:
- the inverted-ness
 
 - 
getHighestValueprotected Integer getHighestValue() Returns the biggest value that has an entry in the label table.- Returns:
- biggest value that has an entry in the label table, or null.
- Since:
- 1.6
 
 - 
getLowestValueprotected Integer getLowestValue() Returns the smallest value that has an entry in the label table.- Returns:
- smallest value that has an entry in the label table, or null.
- Since:
- 1.6
 
 - 
getLowestValueLabelprotected Component getLowestValueLabel() Returns the label that corresponds to the highest slider value in the label table.- Returns:
- the label that corresponds to the highest slider value in the label table
- See Also:
- JSlider.setLabelTable(java.util.Dictionary)
 
 - 
getHighestValueLabelprotected Component getHighestValueLabel() Returns the label that corresponds to the lowest slider value in the label table.- Returns:
- the label that corresponds to the lowest slider value in the label table
- See Also:
- JSlider.setLabelTable(java.util.Dictionary)
 
 - 
recalculateIfInsetsChangedprotected void recalculateIfInsetsChanged() Recalculates if the insets have changed.
 - 
recalculateIfOrientationChangedprotected void recalculateIfOrientationChanged() Recalculates if the orientation has changed.
 - 
paintFocuspublic void paintFocus(Graphics g) Paints focus.- Parameters:
- g- the graphics
 
 - 
paintTrackpublic void paintTrack(Graphics g) Paints track.- Parameters:
- g- the graphics
 
 - 
paintTickspublic void paintTicks(Graphics g) Paints ticks.- Parameters:
- g- the graphics
 
 - 
paintMinorTickForHorizSliderprotected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) Paints minor tick for horizontal slider.- Parameters:
- g- the graphics
- tickBounds- the tick bounds
- x- the x coordinate
 
 - 
paintMajorTickForHorizSliderprotected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) Paints major tick for horizontal slider.- Parameters:
- g- the graphics
- tickBounds- the tick bounds
- x- the x coordinate
 
 - 
paintMinorTickForVertSliderprotected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) Paints minor tick for vertical slider.- Parameters:
- g- the graphics
- tickBounds- the tick bounds
- y- the y coordinate
 
 - 
paintMajorTickForVertSliderprotected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) Paints major tick for vertical slider.- Parameters:
- g- the graphics
- tickBounds- the tick bounds
- y- the y coordinate
 
 - 
paintLabelspublic void paintLabels(Graphics g) Paints the labels.- Parameters:
- g- the graphics
 
 - 
paintHorizontalLabelprotected void paintHorizontalLabel(Graphics g, int value, Component label) Called for every label in the label table. Used to draw the labels for horizontal sliders. The graphics have been translated to labelRect.y already.- Parameters:
- g- the graphics context in which to paint
- value- the value of the slider
- label- the component label in the label table that needs to be painted
- See Also:
- JSlider.setLabelTable(java.util.Dictionary)
 
 - 
paintVerticalLabelprotected void paintVerticalLabel(Graphics g, int value, Component label) Called for every label in the label table. Used to draw the labels for vertical sliders. The graphics have been translated to labelRect.x already.- Parameters:
- g- the graphics context in which to paint
- value- the value of the slider
- label- the component label in the label table that needs to be painted
- See Also:
- JSlider.setLabelTable(java.util.Dictionary)
 
 - 
paintThumbpublic void paintThumb(Graphics g) Paints the thumb.- Parameters:
- g- the graphics
 
 - 
setThumbLocationpublic void setThumbLocation(int x, int y)Sets the thumb location.- Parameters:
- x- the x coordinate
- y- the y coordinate
 
 - 
scrollByBlockpublic void scrollByBlock(int direction) Scrolls by block.- Parameters:
- direction- the direction
 
 - 
scrollByUnitpublic void scrollByUnit(int direction) Scrolls by unit.- Parameters:
- direction- the direction
 
 - 
scrollDueToClickInTrackprotected void scrollDueToClickInTrack(int dir) This function is called when a mousePressed was detected in the track, not in the thumb. The default behavior is to scroll by block. You can override this method to stop it from scrolling or to add additional behavior.- Parameters:
- dir- the direction and number of blocks to scroll
 
 - 
xPositionForValueprotected int xPositionForValue(int value) Returns the x position for a value.- Parameters:
- value- the value
- Returns:
- the x position for a value
 
 - 
yPositionForValueprotected int yPositionForValue(int value) Returns the y position for a value.- Parameters:
- value- the value
- Returns:
- the y position for a value
 
 - 
yPositionForValueprotected int yPositionForValue(int value, int trackY, int trackHeight)Returns the y location for the specified value. No checking is done on the arguments. In particular iftrackHeightis negative undefined results may occur.- Parameters:
- value- the slider value to get the location for
- trackY- y-origin of the track
- trackHeight- the height of the track
- Returns:
- the y location for the specified value of the slider
- Since:
- 1.6
 
 - 
valueForYPositionpublic int valueForYPosition(int yPos) Returns the value at the y position. IfyPosis beyond the track at the bottom or the top, this method sets the value to either the minimum or maximum value of the slider, depending on if the slider is inverted or not.- Parameters:
- yPos- the location of the slider along the y axis
- Returns:
- the value at the y position
 
 - 
valueForXPositionpublic int valueForXPosition(int xPos) Returns the value at the x position. IfxPosis beyond the track at the left or the right, this method sets the value to either the minimum or maximum value of the slider, depending on if the slider is inverted or not.- Parameters:
- xPos- the location of the slider along the x axis
- Returns:
- the value of the x position
 
 
- 
 
-