javax.swing.plaf.basic
Class BasicScrollBarUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.ScrollBarUI
          extended by javax.swing.plaf.basic.BasicScrollBarUI
All Implemented Interfaces:
LayoutManager, SwingConstants
Direct Known Subclasses:
MetalScrollBarUI

public class BasicScrollBarUI
extends ScrollBarUI
implements LayoutManager, SwingConstants

The Basic Look and Feel UI delegate for JScrollBar.


Nested Class Summary
protected  class BasicScrollBarUI.ArrowButtonListener
          A helper class that listens to the two JButtons on each end of the JScrollBar.
protected  class BasicScrollBarUI.ModelListener
          A helper class that listens to the ScrollBar's model for ChangeEvents.
 class BasicScrollBarUI.PropertyChangeHandler
          A helper class that listens to the ScrollBar's properties.
protected  class BasicScrollBarUI.ScrollListener
          A helper class that listens for events from the timer that is used to move the thumb.
protected  class BasicScrollBarUI.TrackListener
          Helper class that listens for movement on the track.
 
Field Summary
protected  BasicScrollBarUI.ArrowButtonListener buttonListener
          The listener that listens to the JButtons.
protected  JButton decrButton
          The JButton that decrements the scrollbar's value.
protected static int DECREASE_HIGHLIGHT
          Indicates that the decrease highlight should be painted.
protected  JButton incrButton
          The JButton that increments the scrollbar's value.
protected static int INCREASE_HIGHLIGHT
          Indicates that the increase highlight should be painted.
protected  boolean isDragging
          FIXME: Use this for something (presumably mouseDragged)
protected  Dimension maximumThumbSize
          The dimensions of the maximum thumb size.
protected  Dimension minimumThumbSize
          The dimensions of the minimum thumb size.
protected  BasicScrollBarUI.ModelListener modelListener
          The listener that listens to the model.
protected static int NO_HIGHLIGHT
          Indicates that no highlight should be painted.
protected  PropertyChangeListener propertyChangeListener
          The listener that listens to the scrollbar for property changes.
protected  JScrollBar scrollbar
          The scrollbar this UI is acting for.
protected  BasicScrollBarUI.ScrollListener scrollListener
          The listener that listens to the timer.
protected  Timer scrollTimer
          The timer used to move the thumb when the mouse is held.
protected  Color thumbColor
          The color of the thumb.
protected  Color thumbDarkShadowColor
          The outer shadow of the thumb.
protected  Color thumbHighlightColor
          The top and left edge color for the thumb.
protected  Color thumbLightShadowColor
          The outer light shadow for the thumb.
protected  Rectangle thumbRect
          The size and position of the thumb.
protected  Color trackColor
          The color of the track.
protected  int trackHighlight
          The current highlight status.
protected  Color trackHighlightColor
          The color that is used when the mouse press occurs in the track.
protected  BasicScrollBarUI.TrackListener trackListener
          The listener that listens for MouseEvents on the track.
protected  Rectangle trackRect
          The size and position of the track.
 
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
BasicScrollBarUI()
           
 
Method Summary
 void addLayoutComponent(String name, Component child)
          This method adds a component to the layout.
protected  void configureScrollBarColors()
          This method configures the scrollbar's colors.
protected  BasicScrollBarUI.ArrowButtonListener createArrowButtonListener()
          This method creates an ArrowButtonListener.
protected  JButton createDecreaseButton(int orientation)
          This method creates a new JButton with the appropriate icon for the orientation.
protected  JButton createIncreaseButton(int orientation)
          This method creates a new JButton with the appropriate icon for the orientation.
protected  BasicScrollBarUI.ModelListener createModelListener()
          This method creates a new ModelListener.
protected  PropertyChangeListener createPropertyChangeListener()
          This method creates a new PropertyChangeListener.
protected  BasicScrollBarUI.ScrollListener createScrollListener()
          This method creates a new ScrollListener.
protected  BasicScrollBarUI.TrackListener createTrackListener()
          This method creates a new TrackListener.
static ComponentUI createUI(JComponent c)
          This method returns a new BasicScrollBarUI.
 Dimension getMaximumSize(JComponent c)
          This method returns the maximum size for this JComponent.
protected  Dimension getMaximumThumbSize()
          This method returns the maximum thumb size.
 Dimension getMinimumSize(JComponent c)
          This method returns the minimum size for this JComponent.
protected  Dimension getMinimumThumbSize()
          This method returns the minimum thumb size.
 Dimension getPreferredSize(JComponent c)
          This method returns a cached value of the preferredSize.
 boolean getSupportsAbsolutePositioning()
          Indicates whether the user can position the thumb with a mouse click (i.e. middle button).
protected  Rectangle getThumbBounds()
          This method returns the thumb's bounds based on the current value of the scrollbar.
protected  Rectangle getTrackBounds()
          This method calculates the bounds of the track.
protected  void installComponents()
          This method installs any addition Components that are a part of or related to this scrollbar.
protected  void installDefaults()
          This method installs the defaults for the scrollbar specified by the Basic Look and Feel.
protected  void installKeyboardActions()
          Installs the input map from the look and feel defaults, and a corresponding action map.
protected  void installListeners()
          This method installs any listeners for the scrollbar.
 void installUI(JComponent c)
          This method installs the UI for the component.
 boolean isThumbRollover()
          Returns true if the mouse is over the thumb.
 void layoutContainer(Container scrollbarContainer)
          This method lays out the scrollbar.
protected  void layoutHScrollbar(JScrollBar sb)
          This method lays out the scrollbar horizontally.
protected  void layoutVScrollbar(JScrollBar sb)
          This method lays out the scrollbar vertically.
 Dimension minimumLayoutSize(Container scrollbarContainer)
          This method returns the minimum size required for the layout.
 void paint(Graphics g, JComponent c)
          This method is called when the component is painted.
protected  void paintDecreaseHighlight(Graphics g)
          This method is called when repainting and the mouse is pressed in the track.
protected  void paintIncreaseHighlight(Graphics g)
          This method is called when repainting and the mouse is pressed in the track.
protected  void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
          This method paints the thumb.
protected  void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
          This method paints the track.
 Dimension preferredLayoutSize(Container scrollbarContainer)
          This method returns the preferred size for the layout.
 void removeLayoutComponent(Component child)
          This method removes a child component from the layout.
protected  void scrollByBlock(int direction)
          The method scrolls the thumb by a block in the direction specified.
protected  void scrollByUnit(int direction)
          The method scrolls the thumb by a unit in the direction specified.
protected  void setThumbBounds(int x, int y, int width, int height)
          This method sets the thumb's bounds.
protected  void setThumbRollover(boolean active)
          Set thumbRollover to active.
protected  void uninstallComponents()
          This method uninstalls any components that are a part of or related to this scrollbar.
protected  void uninstallDefaults()
          This method uninstalls any defaults that this scrollbar acquired from the Basic Look and Feel defaults.
protected  void uninstallKeyboardActions()
          Uninstalls the input map and action map installed by installKeyboardActions().
protected  void uninstallListeners()
          This method uninstalls any listeners that were registered during install.
 void uninstallUI(JComponent c)
          This method uninstalls the UI.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buttonListener

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


modelListener

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


propertyChangeListener

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


scrollListener

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


trackListener

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


decrButton

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


incrButton

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


maximumThumbSize

protected Dimension maximumThumbSize
The dimensions of the maximum thumb size.


minimumThumbSize

protected Dimension minimumThumbSize
The dimensions of the minimum thumb size.


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.


trackHighlightColor

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


trackColor

protected Color trackColor
The color of the track.


trackRect

protected Rectangle trackRect
The size and position of the track.


thumbRect

protected Rectangle thumbRect
The size and position of the thumb.


DECREASE_HIGHLIGHT

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

See Also:
Constant Field Values

INCREASE_HIGHLIGHT

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

See Also:
Constant Field Values

NO_HIGHLIGHT

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

See Also:
Constant Field Values

trackHighlight

protected int trackHighlight
The current highlight status.


isDragging

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


scrollTimer

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


scrollbar

protected JScrollBar scrollbar
The scrollbar this UI is acting for.

Constructor Detail

BasicScrollBarUI

public BasicScrollBarUI()
Method Detail

addLayoutComponent

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

Specified by:
addLayoutComponent in interface LayoutManager
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.

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.

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.

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.

Overrides:
getMaximumSize in class ComponentUI
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.

Overrides:
getMinimumSize in class ComponentUI
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).

Overrides:
getPreferredSize in class ComponentUI
Parameters:
c - The JComponent to measure.
Returns:
The preferredSize.

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 JScrollBar component has the focus, which is rare.


uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls the input map and action map installed by installKeyboardActions().


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.

Overrides:
installUI in class ComponentUI
Parameters:
c - The JComponent to install.
See Also:
ComponentUI.uninstallUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

layoutContainer

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

Specified by:
layoutContainer in interface LayoutManager
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.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
scrollbarContainer - The Container that is laid out.
Returns:
The minimum size.
See Also:
LayoutManager.preferredLayoutSize(Container)

paint

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

Overrides:
paint in class ComponentUI
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.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
scrollbarContainer - The Container to find a size for.
Returns:
The preferred size for the layout.
See Also:
LayoutManager.minimumLayoutSize(Container)

removeLayoutComponent

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

Specified by:
removeLayoutComponent in interface LayoutManager
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.

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.


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.

Overrides:
uninstallUI in class ComponentUI
Parameters:
c - The Component to uninstall for.
See Also:
ComponentUI.installUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

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

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

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