public class

BasicScrollBarUI

extends ScrollBarUI
implements LayoutManager SwingConstants
java.lang.Object
   ↳ javax.swing.plaf.ComponentUI
     ↳ javax.swing.plaf.ScrollBarUI
       ↳ javax.swing.plaf.basic.BasicScrollBarUI
Known Direct Subclasses

Class Overview

Implementation of ScrollBarUI for the Basic Look and Feel

Summary

Nested Classes
class BasicScrollBarUI.ArrowButtonListener Listener for cursor keys. 
class BasicScrollBarUI.ModelListener A listener to listen for model changes. 
class BasicScrollBarUI.PropertyChangeHandler  
class BasicScrollBarUI.ScrollListener Listener for scrolling events initiated in the ScrollPane
class BasicScrollBarUI.TrackListener Track mouse drags. 
Constants
int DECREASE_HIGHLIGHT
int INCREASE_HIGHLIGHT
int NO_HIGHLIGHT
[Expand]
Inherited Constants
From interface javax.swing.SwingConstants
Fields
protected BasicScrollBarUI.ArrowButtonListener buttonListener
protected JButton decrButton
protected JButton incrButton
protected boolean isDragging
protected Dimension maximumThumbSize
protected Dimension minimumThumbSize
protected BasicScrollBarUI.ModelListener modelListener
protected PropertyChangeListener propertyChangeListener
protected BasicScrollBarUI.ScrollListener scrollListener
protected Timer scrollTimer
protected JScrollBar scrollbar
protected Color thumbColor
protected Color thumbDarkShadowColor
protected Color thumbHighlightColor
protected Color thumbLightShadowColor
protected Rectangle thumbRect
protected Color trackColor
protected int trackHighlight
protected Color trackHighlightColor
protected BasicScrollBarUI.TrackListener trackListener
protected Rectangle trackRect
Public Constructors
BasicScrollBarUI()
Public Methods
void addLayoutComponent(String name, Component child)
If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
static ComponentUI createUI(JComponent c)
Dimension getMaximumSize(JComponent c)
Returns the specified component's maximum size appropriate for the look and feel.
Dimension getPreferredSize(JComponent c)
A vertical scrollbar's preferred width is the maximum of preferred widths of the (non null) increment/decrement buttons, and the minimum width of the thumb.
boolean getSupportsAbsolutePositioning()
Indicates whether the user can absolutely position the thumb with a mouse gesture (usually the middle mouse button).
void installUI(JComponent c)
Configures the specified component appropriate for the look and feel.
boolean isThumbRollover()
Returns true if the mouse is currently over the thumb.
void layoutContainer(Container scrollbarContainer)
Lays out the specified container.
Dimension minimumLayoutSize(Container scrollbarContainer)
Calculates the minimum size dimensions for the specified container, given the components it contains.
void paint(Graphics g, JComponent c)
Paints the specified component appropriate for the look and feel.
Dimension preferredLayoutSize(Container scrollbarContainer)
Calculates the preferred size dimensions for the specified container, given the components it contains.
void removeLayoutComponent(Component child)
Removes the specified component from the layout.
void uninstallUI(JComponent c)
Reverses configuration which was done on the specified component during installUI.
Protected Methods
void configureScrollBarColors()
BasicScrollBarUI.ArrowButtonListener createArrowButtonListener()
JButton createDecreaseButton(int orientation)
JButton createIncreaseButton(int orientation)
BasicScrollBarUI.ModelListener createModelListener()
PropertyChangeListener createPropertyChangeListener()
BasicScrollBarUI.ScrollListener createScrollListener()
BasicScrollBarUI.TrackListener createTrackListener()
Dimension getMaximumThumbSize()
Return the largest acceptable size for the thumb.
Dimension getMinimumThumbSize()
Return the smallest acceptable size for the thumb.
Rectangle getThumbBounds()
Return the current size/location of the thumb.
Rectangle getTrackBounds()
Returns the current bounds of the track, i.e.
void installComponents()
void installDefaults()
void installKeyboardActions()
void installListeners()
void layoutHScrollbar(JScrollBar sb)
void layoutVScrollbar(JScrollBar sb)
void paintDecreaseHighlight(Graphics g)
void paintIncreaseHighlight(Graphics g)
void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
void scrollByBlock(int direction)
void scrollByUnit(int direction)
void setThumbBounds(int x, int y, int width, int height)
Set the bounds of the thumb and force a repaint that includes the old thumbBounds and the new one.
void setThumbRollover(boolean active)
Sets whether or not the mouse is currently over the thumb.
void uninstallComponents()
void uninstallDefaults()
void uninstallKeyboardActions()
void uninstallListeners()
[Expand]
Inherited Methods
From class javax.swing.plaf.ComponentUI
From class java.lang.Object
From interface java.awt.LayoutManager

Constants

protected static final int DECREASE_HIGHLIGHT

Constant Value: 1 (0x00000001)

protected static final int INCREASE_HIGHLIGHT

Constant Value: 2 (0x00000002)

protected static final int NO_HIGHLIGHT

Constant Value: 0 (0x00000000)

Fields

protected BasicScrollBarUI.ArrowButtonListener buttonListener

protected JButton decrButton

protected JButton incrButton

protected boolean isDragging

protected Dimension maximumThumbSize

protected Dimension minimumThumbSize

protected BasicScrollBarUI.ModelListener modelListener

protected PropertyChangeListener propertyChangeListener

protected BasicScrollBarUI.ScrollListener scrollListener

protected Timer scrollTimer

protected JScrollBar scrollbar

protected Color thumbColor

protected Color thumbDarkShadowColor

protected Color thumbHighlightColor

protected Color thumbLightShadowColor

protected Rectangle thumbRect

protected Color trackColor

protected int trackHighlight

protected Color trackHighlightColor

protected BasicScrollBarUI.TrackListener trackListener

protected Rectangle trackRect

Public Constructors

public BasicScrollBarUI ()

Public Methods

public void addLayoutComponent (String name, Component child)

If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.

Parameters
name the string to be associated with the component
child the component to be added

public static ComponentUI createUI (JComponent c)

public Dimension getMaximumSize (JComponent c)

Returns the specified component's maximum size appropriate for the look and feel. If null is returned, the maximum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes getPreferredSize and returns that value.

Parameters
c The JScrollBar that's delegating this method to us.
Returns
  • new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);

public Dimension getPreferredSize (JComponent c)

A vertical scrollbar's preferred width is the maximum of preferred widths of the (non null) increment/decrement buttons, and the minimum width of the thumb. The preferred height is the sum of the preferred heights of the same parts. The basis for the preferred size of a horizontal scrollbar is similar.

The preferredSize is only computed once, subsequent calls to this method just return a cached size.

Parameters
c the JScrollBar that's delegating this method to us
Returns
  • the preferred size of a Basic JScrollBar

public boolean getSupportsAbsolutePositioning ()

Indicates whether the user can absolutely position the thumb with a mouse gesture (usually the middle mouse button).

Returns
  • true if a mouse gesture can absolutely position the thumb

public void installUI (JComponent c)

Configures the specified component appropriate for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:

  1. Install any default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.

Parameters
c the component where this UI delegate is being installed

public boolean isThumbRollover ()

Returns true if the mouse is currently over the thumb.

Returns
  • true if the thumb is currently active

public void layoutContainer (Container scrollbarContainer)

Lays out the specified container.

Parameters
scrollbarContainer the container to be laid out

public Dimension minimumLayoutSize (Container scrollbarContainer)

Calculates the minimum size dimensions for the specified container, given the components it contains.

Parameters
scrollbarContainer the component to be laid out

public void paint (Graphics g, JComponent c)

Paints the specified component appropriate for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Parameters
g the Graphics context in which to paint
c the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

public Dimension preferredLayoutSize (Container scrollbarContainer)

Calculates the preferred size dimensions for the specified container, given the components it contains.

Parameters
scrollbarContainer the container to be laid out

public void removeLayoutComponent (Component child)

Removes the specified component from the layout.

Parameters
child the component to be removed

public void uninstallUI (JComponent c)

Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:

  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.

Parameters
c the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

Protected Methods

protected void configureScrollBarColors ()

protected BasicScrollBarUI.ArrowButtonListener createArrowButtonListener ()

protected JButton createDecreaseButton (int orientation)

protected JButton createIncreaseButton (int orientation)

protected BasicScrollBarUI.ModelListener createModelListener ()

protected PropertyChangeListener createPropertyChangeListener ()

protected BasicScrollBarUI.ScrollListener createScrollListener ()

protected BasicScrollBarUI.TrackListener createTrackListener ()

protected Dimension getMaximumThumbSize ()

Return the largest acceptable size for the thumb. To create a fixed size thumb one make this method and getMinimumThumbSize return the same value.

Warning : the value returned by this method should not be be modified, it's a shared static constant.

Returns
  • The largest acceptable size for the thumb.

protected Dimension getMinimumThumbSize ()

Return the smallest acceptable size for the thumb. If the scrollbar becomes so small that this size isn't available, the thumb will be hidden.

Warning : the value returned by this method should not be be modified, it's a shared static constant.

Returns
  • The smallest acceptable size for the thumb.

protected Rectangle getThumbBounds ()

Return the current size/location of the thumb.

Warning : the value returned by this method should not be be modified, it's a reference to the actual rectangle, not a copy.

Returns
  • The current size/location of the thumb.

protected Rectangle getTrackBounds ()

Returns the current bounds of the track, i.e. the space in between the increment and decrement buttons, less the insets. The value returned by this method is updated each time the scrollbar is laid out (validated).

Warning : the value returned by this method should not be be modified, it's a reference to the actual rectangle, not a copy.

Returns
  • the current bounds of the scrollbar track

protected void installComponents ()

protected void installDefaults ()

protected void installKeyboardActions ()

protected void installListeners ()

protected void layoutHScrollbar (JScrollBar sb)

protected void layoutVScrollbar (JScrollBar sb)

protected void paintDecreaseHighlight (Graphics g)

protected void paintIncreaseHighlight (Graphics g)

protected void paintThumb (Graphics g, JComponent c, Rectangle thumbBounds)

protected void paintTrack (Graphics g, JComponent c, Rectangle trackBounds)

protected void scrollByBlock (int direction)

protected void scrollByUnit (int direction)

protected void setThumbBounds (int x, int y, int width, int height)

Set the bounds of the thumb and force a repaint that includes the old thumbBounds and the new one.

See Also

protected void setThumbRollover (boolean active)

Sets whether or not the mouse is currently over the thumb.

Parameters
active True indicates the thumb is currently active.

protected void uninstallComponents ()

protected void uninstallDefaults ()

protected void uninstallKeyboardActions ()

protected void uninstallListeners ()