javax.swing.plaf.basic

Class BasicScrollBarUI

public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, SwingConstants

The Basic Look and Feel UI delegate for JScrollBar.
Nested Class Summary
protected classBasicScrollBarUI.ArrowButtonListener
A helper class that listens to the two JButtons on each end of the JScrollBar.
protected classBasicScrollBarUI.ModelListener
A helper class that listens to the ScrollBar's model for ChangeEvents.
classBasicScrollBarUI.PropertyChangeHandler
A helper class that listens to the ScrollBar's properties.
protected classBasicScrollBarUI.ScrollListener
A helper class that listens for events from the timer that is used to move the thumb.
protected classBasicScrollBarUI.TrackListener
Helper class that listens for movement on the track.
Field Summary
protected BasicScrollBarUI.ArrowButtonListenerbuttonListener
The listener that listens to the JButtons.
protected JButtondecrButton
The JButton that decrements the scrollbar's value.
protected static intDECREASE_HIGHLIGHT
Indicates that the decrease highlight should be painted.
protected JButtonincrButton
The JButton that increments the scrollbar's value.
protected booleanisDragging
FIXME: Use this for something (presumably mouseDragged)
protected static intINCREASE_HIGHLIGHT
Indicates that the increase highlight should be painted.
protected DimensionmaximumThumbSize
The dimensions of the maximum thumb size.
protected DimensionminimumThumbSize
The dimensions of the minimum thumb size.
protected BasicScrollBarUI.ModelListenermodelListener
The listener that listens to the model.
protected static intNO_HIGHLIGHT
Indicates that no highlight should be painted.
protected PropertyChangeListenerpropertyChangeListener
The listener that listens to the scrollbar for property changes.
protected JScrollBarscrollbar
The scrollbar this UI is acting for.
protected BasicScrollBarUI.ScrollListenerscrollListener
The listener that listens to the timer.
protected TimerscrollTimer
The timer used to move the thumb when the mouse is held.
protected ColorthumbColor
The color of the thumb.
protected ColorthumbDarkShadowColor
The outer shadow of the thumb.
protected ColorthumbHighlightColor
The top and left edge color for the thumb.
protected ColorthumbLightShadowColor
The outer light shadow for the thumb.
protected RectanglethumbRect
The size and position of the thumb.
protected ColortrackColor
The color of the track.
protected inttrackHighlight
The current highlight status.
protected ColortrackHighlightColor
The color that is used when the mouse press occurs in the track.
protected BasicScrollBarUI.TrackListenertrackListener
The listener that listens for MouseEvents on the track.
protected RectangletrackRect
The size and position of the track.
Method Summary
voidaddLayoutComponent(String name, Component child)
This method adds a component to the layout.
protected voidconfigureScrollBarColors()
This method configures the scrollbar's colors.
protected BasicScrollBarUI.ArrowButtonListenercreateArrowButtonListener()
This method creates an ArrowButtonListener.
protected JButtoncreateDecreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.
protected JButtoncreateIncreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.
protected BasicScrollBarUI.ModelListenercreateModelListener()
This method creates a new ModelListener.
protected PropertyChangeListenercreatePropertyChangeListener()
This method creates a new PropertyChangeListener.
protected BasicScrollBarUI.ScrollListenercreateScrollListener()
This method creates a new ScrollListener.
protected BasicScrollBarUI.TrackListenercreateTrackListener()
This method creates a new TrackListener.
static ComponentUIcreateUI(JComponent c)
This method returns a new BasicScrollBarUI.
DimensiongetMaximumSize(JComponent c)
This method returns the maximum size for this JComponent.
protected DimensiongetMaximumThumbSize()
This method returns the maximum thumb size.
DimensiongetMinimumSize(JComponent c)
This method returns the minimum size for this JComponent.
protected DimensiongetMinimumThumbSize()
This method returns the minimum thumb size.
DimensiongetPreferredSize(JComponent c)
This method returns a cached value of the preferredSize.
booleangetSupportsAbsolutePositioning()
Indicates whether the user can position the thumb with a mouse click (i.e. middle button).
protected RectanglegetThumbBounds()
This method returns the thumb's bounds based on the current value of the scrollbar.
protected RectanglegetTrackBounds()
This method calculates the bounds of the track.
protected voidinstallComponents()
This method installs any addition Components that are a part of or related to this scrollbar.
protected voidinstallDefaults()
This method installs the defaults for the scrollbar specified by the Basic Look and Feel.
protected voidinstallKeyboardActions()
Installs the input map from the look and feel defaults, and a corresponding action map.
protected voidinstallListeners()
This method installs any listeners for the scrollbar.
voidinstallUI(JComponent c)
This method installs the UI for the component.
booleanisThumbRollover()
Returns true if the mouse is over the thumb.
voidlayoutContainer(Container scrollbarContainer)
This method lays out the scrollbar.
protected voidlayoutHScrollbar(JScrollBar sb)
This method lays out the scrollbar horizontally.
protected voidlayoutVScrollbar(JScrollBar sb)
This method lays out the scrollbar vertically.
DimensionminimumLayoutSize(Container scrollbarContainer)
This method returns the minimum size required for the layout.
voidpaint(Graphics g, JComponent c)
This method is called when the component is painted.
protected voidpaintDecreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track.
protected voidpaintIncreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track.
protected voidpaintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
This method paints the thumb.
protected voidpaintTrack(Graphics g, JComponent c, Rectangle trackBounds)
This method paints the track.
DimensionpreferredLayoutSize(Container scrollbarContainer)
This method returns the preferred size for the layout.
voidremoveLayoutComponent(Component child)
This method removes a child component from the layout.
protected voidscrollByBlock(int direction)
The method scrolls the thumb by a block in the direction specified.
protected voidscrollByUnit(int direction)
The method scrolls the thumb by a unit in the direction specified.
protected voidsetThumbBounds(int x, int y, int width, int height)
This method sets the thumb's bounds.
protected voidsetThumbRollover(boolean active)
Set thumbRollover to active.
protected voiduninstallComponents()
This method uninstalls any components that are a part of or related to this scrollbar.
protected voiduninstallDefaults()
This method uninstalls any defaults that this scrollbar acquired from the Basic Look and Feel defaults.
protected voiduninstallKeyboardActions()
Uninstalls the input map and action map installed by {@link #installKeyboardActions()}.
protected voiduninstallListeners()
This method uninstalls any listeners that were registered during install.
voiduninstallUI(JComponent c)
This method uninstalls the UI.

Field Detail

buttonListener

protected BasicScrollBarUI.ArrowButtonListener buttonListener
The listener that listens to the JButtons.

decrButton

protected JButton decrButton
The JButton that decrements the scrollbar's value.

DECREASE_HIGHLIGHT

protected static final int DECREASE_HIGHLIGHT
Indicates that the decrease highlight should be painted.

incrButton

protected JButton incrButton
The JButton that increments the scrollbar's value.

isDragging

protected boolean isDragging
FIXME: Use this for something (presumably mouseDragged)

INCREASE_HIGHLIGHT

protected static final int INCREASE_HIGHLIGHT
Indicates that the increase highlight should be painted.

maximumThumbSize

protected Dimension maximumThumbSize
The dimensions of the maximum thumb size.

minimumThumbSize

protected Dimension minimumThumbSize
The dimensions of the minimum thumb size.

modelListener

protected BasicScrollBarUI.ModelListener modelListener
The listener that listens to the model.

NO_HIGHLIGHT

protected static final int NO_HIGHLIGHT
Indicates that no highlight should be painted.

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
The listener that listens to the scrollbar for property changes.

scrollbar

protected JScrollBar scrollbar
The scrollbar this UI is acting for.

scrollListener

protected BasicScrollBarUI.ScrollListener scrollListener
The listener that listens to the timer.

scrollTimer

protected Timer scrollTimer
The timer used to move the thumb when the mouse is held.

thumbColor

protected Color thumbColor
The color of the thumb.

thumbDarkShadowColor

protected Color thumbDarkShadowColor
The outer shadow of the thumb.

thumbHighlightColor

protected Color thumbHighlightColor
The top and left edge color for the thumb.

thumbLightShadowColor

protected Color thumbLightShadowColor
The outer light shadow for the thumb.

thumbRect

protected Rectangle thumbRect
The size and position of the thumb.

trackColor

protected Color trackColor
The color of the track.

trackHighlight

protected int trackHighlight
The current highlight status.

trackHighlightColor

protected Color trackHighlightColor
The color that is used when the mouse press occurs in the track.

trackListener

protected BasicScrollBarUI.TrackListener trackListener
The listener that listens for MouseEvents on the track.

trackRect

protected Rectangle trackRect
The size and position of the track.

Method Detail

addLayoutComponent

public void addLayoutComponent(String name, Component child)
This method adds a component to the layout.

Parameters: name The name to associate with the component that is added. child The Component to add.

configureScrollBarColors

protected void configureScrollBarColors()
This method configures the scrollbar's colors. This can be done by looking up the standard colors from the Look and Feel defaults.

createArrowButtonListener

protected BasicScrollBarUI.ArrowButtonListener createArrowButtonListener()
This method creates an ArrowButtonListener.

Returns: A new ArrowButtonListener.

createDecreaseButton

protected JButton createDecreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.

Parameters: orientation The orientation this JButton uses.

Returns: The decrease JButton.

createIncreaseButton

protected JButton createIncreaseButton(int orientation)
This method creates a new JButton with the appropriate icon for the orientation.

Parameters: orientation The orientation this JButton uses.

Returns: The increase JButton.

createModelListener

protected BasicScrollBarUI.ModelListener createModelListener()
This method creates a new ModelListener.

Returns: A new ModelListener.

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
This method creates a new PropertyChangeListener.

Returns: A new PropertyChangeListener.

createScrollListener

protected BasicScrollBarUI.ScrollListener createScrollListener()
This method creates a new ScrollListener.

Returns: A new ScrollListener.

createTrackListener

protected BasicScrollBarUI.TrackListener createTrackListener()
This method creates a new TrackListener.

Returns: A new TrackListener.

createUI

public static ComponentUI createUI(JComponent c)
This method returns a new BasicScrollBarUI.

Parameters: c The JComponent to create a UI for.

Returns: A new BasicScrollBarUI.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size for this JComponent.

Parameters: c The JComponent to measure the maximum size for.

Returns: The maximum size for the component.

getMaximumThumbSize

protected Dimension getMaximumThumbSize()
This method returns the maximum thumb size.

Returns: The maximum thumb size.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size for this JComponent.

Parameters: c The JComponent to measure the minimum size for.

Returns: The minimum size for the component.

getMinimumThumbSize

protected Dimension getMinimumThumbSize()
This method returns the minimum thumb size.

Returns: The minimum thumb size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
This method returns a cached value of the preferredSize. The only restrictions are: If the scrollbar is horizontal, the height should be the maximum of the height of the JButtons and the minimum width of the thumb. For vertical scrollbars, the calculation is similar (swap width for height and vice versa).

Parameters: c The JComponent to measure.

Returns: The preferredSize.

getSupportsAbsolutePositioning

public boolean getSupportsAbsolutePositioning()
Indicates whether the user can position the thumb with a mouse click (i.e. middle button).

Returns: true if the user can position the thumb with a mouse click.

Since: 1.5

getThumbBounds

protected Rectangle getThumbBounds()
This method returns the thumb's bounds based on the current value of the scrollbar. This method updates the cached value and returns that.

Returns: The thumb bounds.

getTrackBounds

protected Rectangle getTrackBounds()
This method calculates the bounds of the track. This method updates the cached value and returns it.

Returns: The track's bounds.

installComponents

protected void installComponents()
This method installs any addition Components that are a part of or related to this scrollbar.

installDefaults

protected void installDefaults()
This method installs the defaults for the scrollbar specified by the Basic Look and Feel.

installKeyboardActions

protected void installKeyboardActions()
Installs the input map from the look and feel defaults, and a corresponding action map. Note the the keyboard bindings will only work when the {@link JScrollBar} component has the focus, which is rare.

installListeners

protected void installListeners()
This method installs any listeners for the scrollbar. This method also installs listeners for things such as the JButtons and the timer.

installUI

public void installUI(JComponent c)
This method installs the UI for the component. This can include setting up listeners, defaults, and components. This also includes initializing any data objects.

Parameters: c The JComponent to install.

isThumbRollover

public boolean isThumbRollover()
Returns true if the mouse is over the thumb.

Returns: true if the mouse is over the thumb.

Since: 1.5

layoutContainer

public void layoutContainer(Container scrollbarContainer)
This method lays out the scrollbar.

Parameters: scrollbarContainer The Container to layout.

layoutHScrollbar

protected void layoutHScrollbar(JScrollBar sb)
This method lays out the scrollbar horizontally.

Parameters: sb The JScrollBar to layout.

layoutVScrollbar

protected void layoutVScrollbar(JScrollBar sb)
This method lays out the scrollbar vertically.

Parameters: sb The JScrollBar to layout.

minimumLayoutSize

public Dimension minimumLayoutSize(Container scrollbarContainer)
This method returns the minimum size required for the layout.

Parameters: scrollbarContainer The Container that is laid out.

Returns: The minimum size.

paint

public void paint(Graphics g, JComponent c)
This method is called when the component is painted.

Parameters: g The Graphics object to paint with. c The JComponent to paint.

paintDecreaseHighlight

protected void paintDecreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track. It paints the track below the thumb with the trackHighlight color.

Parameters: g The Graphics object to paint with.

paintIncreaseHighlight

protected void paintIncreaseHighlight(Graphics g)
This method is called when repainting and the mouse is pressed in the track. It paints the track above the thumb with the trackHighlight color.

Parameters: g The Graphics objet to paint with.

paintThumb

protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
This method paints the thumb.

Parameters: g The Graphics object to paint with. c The Component that is being painted. thumbBounds The thumb bounds.

paintTrack

protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
This method paints the track.

Parameters: g The Graphics object to paint with. c The JComponent being painted. trackBounds The track's bounds.

preferredLayoutSize

public Dimension preferredLayoutSize(Container scrollbarContainer)
This method returns the preferred size for the layout.

Parameters: scrollbarContainer The Container to find a size for.

Returns: The preferred size for the layout.

removeLayoutComponent

public void removeLayoutComponent(Component child)
This method removes a child component from the layout.

Parameters: child The child to remove.

scrollByBlock

protected void scrollByBlock(int direction)
The method scrolls the thumb by a block in the direction specified.

Parameters: direction The direction to scroll.

scrollByUnit

protected void scrollByUnit(int direction)
The method scrolls the thumb by a unit in the direction specified.

Parameters: direction The direction to scroll.

setThumbBounds

protected void setThumbBounds(int x, int y, int width, int height)
This method sets the thumb's bounds.

Parameters: x The X position of the thumb. y The Y position of the thumb. width The width of the thumb. height The height of the thumb.

setThumbRollover

protected void setThumbRollover(boolean active)
Set thumbRollover to active. This indicates whether or not the mouse is over the thumb.

Parameters: active - true if the mouse is over the thumb.

Since: 1.5

uninstallComponents

protected void uninstallComponents()
This method uninstalls any components that are a part of or related to this scrollbar.

uninstallDefaults

protected void uninstallDefaults()
This method uninstalls any defaults that this scrollbar acquired from the Basic Look and Feel defaults.

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls the input map and action map installed by {@link #installKeyboardActions()}.

uninstallListeners

protected void uninstallListeners()
This method uninstalls any listeners that were registered during install.

uninstallUI

public void uninstallUI(JComponent c)
This method uninstalls the UI. This includes removing any defaults, listeners, and components that this UI may have initialized. It also nulls any instance data.

Parameters: c The Component to uninstall for.