javax.swing.plaf.metal
Class MetalScrollBarUI

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

public class MetalScrollBarUI
extends BasicScrollBarUI

A UI delegate for the JScrollBar component.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicScrollBarUI
BasicScrollBarUI.ArrowButtonListener, BasicScrollBarUI.ModelListener, BasicScrollBarUI.PropertyChangeHandler, BasicScrollBarUI.ScrollListener, BasicScrollBarUI.TrackListener
 
Field Summary
protected  MetalScrollButton decreaseButton
          The button that decreases the value in the scroll bar.
static String FREE_STANDING_PROP
          The name for the 'free standing' property.
protected  MetalScrollButton increaseButton
          The button that increases the value in the scroll bar.
protected  boolean isFreeStanding
          A flag that indicates whether the scroll bar is "free standing", which means it has complete borders and can be used anywhere in the UI.
protected  int scrollBarWidth
          The scroll bar width.
 
Fields inherited from class javax.swing.plaf.basic.BasicScrollBarUI
buttonListener, decrButton, DECREASE_HIGHLIGHT, incrButton, INCREASE_HIGHLIGHT, isDragging, maximumThumbSize, minimumThumbSize, modelListener, NO_HIGHLIGHT, propertyChangeListener, scrollbar, scrollListener, scrollTimer, thumbColor, thumbDarkShadowColor, thumbHighlightColor, thumbLightShadowColor, thumbRect, trackColor, trackHighlight, trackHighlightColor, trackListener, trackRect
 
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
MetalScrollBarUI()
          Constructs a new instance of MetalScrollBarUI, with no specific initialisation.
 
Method Summary
protected  JButton createDecreaseButton(int orientation)
          Creates a new button to use as the control at the lower end of the JScrollBar.
protected  JButton createIncreaseButton(int orientation)
          Creates a new button to use as the control at the upper end of the JScrollBar.
protected  PropertyChangeListener createPropertyChangeListener()
          Creates a property change listener for the delegate to use.
static ComponentUI createUI(JComponent component)
          Returns a new instance of MetalScrollBarUI.
protected  Dimension getMinimumThumbSize()
          Returns the minimum thumb size.
 Dimension getPreferredSize(JComponent c)
          Returns the preferredSize for the specified scroll bar.
protected  void installDefaults()
          Installs the defaults.
protected  void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
          Paints the slider button of the ScrollBar.
protected  void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
          Paints the track for the scrollbar.
 
Methods inherited from class javax.swing.plaf.basic.BasicScrollBarUI
addLayoutComponent, configureScrollBarColors, createArrowButtonListener, createModelListener, createScrollListener, createTrackListener, getMaximumSize, getMaximumThumbSize, getMinimumSize, getSupportsAbsolutePositioning, getThumbBounds, getTrackBounds, installComponents, installKeyboardActions, installListeners, installUI, isThumbRollover, layoutContainer, layoutHScrollbar, layoutVScrollbar, minimumLayoutSize, paint, paintDecreaseHighlight, paintIncreaseHighlight, preferredLayoutSize, removeLayoutComponent, scrollByBlock, scrollByUnit, setThumbBounds, setThumbRollover, uninstallComponents, uninstallDefaults, uninstallKeyboardActions, uninstallListeners, uninstallUI
 
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

FREE_STANDING_PROP

public static final String FREE_STANDING_PROP
The name for the 'free standing' property.

See Also:
Constant Field Values

increaseButton

protected MetalScrollButton increaseButton
The button that increases the value in the scroll bar.


decreaseButton

protected MetalScrollButton decreaseButton
The button that decreases the value in the scroll bar.


scrollBarWidth

protected int scrollBarWidth
The scroll bar width.


isFreeStanding

protected boolean isFreeStanding
A flag that indicates whether the scroll bar is "free standing", which means it has complete borders and can be used anywhere in the UI. A scroll bar which is not free standing has borders missing from one side, and relies on being part of another container with its own borders to look right visually.

Constructor Detail

MetalScrollBarUI

public MetalScrollBarUI()
Constructs a new instance of MetalScrollBarUI, with no specific initialisation.

Method Detail

createUI

public static ComponentUI createUI(JComponent component)
Returns a new instance of MetalScrollBarUI.

Parameters:
component - the component for which we return an UI instance
Returns:
An instance of MetalScrollBarUI

installDefaults

protected void installDefaults()
Installs the defaults.

Overrides:
installDefaults in class BasicScrollBarUI

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates a property change listener for the delegate to use. This overrides the method to provide a custom listener for the MetalLookAndFeel that can handle the JScrollBar.isFreeStanding property.

Overrides:
createPropertyChangeListener in class BasicScrollBarUI
Returns:
A property change listener.

createDecreaseButton

protected JButton createDecreaseButton(int orientation)
Creates a new button to use as the control at the lower end of the JScrollBar. This method assigns the new button (an instance of MetalScrollButton to the decreaseButton field, and also returns the button. The button width is determined by the ScrollBar.width setting in the UI defaults.

Overrides:
createDecreaseButton in class BasicScrollBarUI
Parameters:
orientation - the orientation of the button (SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST).
Returns:
The button.

createIncreaseButton

protected JButton createIncreaseButton(int orientation)
Creates a new button to use as the control at the upper end of the JScrollBar. This method assigns the new button (an instance of MetalScrollButton to the increaseButton field, and also returns the button. The button width is determined by the ScrollBar.width setting in the UI defaults.

Overrides:
createIncreaseButton in class BasicScrollBarUI
Parameters:
orientation - the orientation of the button (SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST).
Returns:
The button.

paintTrack

protected void paintTrack(Graphics g,
                          JComponent c,
                          Rectangle trackBounds)
Paints the track for the scrollbar.

Overrides:
paintTrack in class BasicScrollBarUI
Parameters:
g - the graphics device.
c - the component.
trackBounds - the track bounds.

paintThumb

protected void paintThumb(Graphics g,
                          JComponent c,
                          Rectangle thumbBounds)
Paints the slider button of the ScrollBar.

Overrides:
paintThumb in class BasicScrollBarUI
Parameters:
g - the Graphics context to use
c - the JComponent on which we paint
thumbBounds - the rectangle that is the slider button

getMinimumThumbSize

protected Dimension getMinimumThumbSize()
Returns the minimum thumb size. For a free standing scroll bar the minimum size is 17 x 17 pixels, whereas for a non free standing scroll bar the minimum size is 15 x 15 pixels.

Overrides:
getMinimumThumbSize in class BasicScrollBarUI
Returns:
The minimum thumb size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns the preferredSize for the specified scroll bar. For a vertical scrollbar the height is the sum of the preferred heights of the buttons plus 30. The width is fetched from the UIManager property ScrollBar.width. For horizontal scrollbars the width is the sum of the preferred widths of the buttons plus 30. The height is fetched from the UIManager property ScrollBar.height.

Overrides:
getPreferredSize in class BasicScrollBarUI
Parameters:
c - the scrollbar for which to calculate the preferred size
Returns:
the preferredSize for the specified scroll bar