javax.swing.plaf.metal

Class MetalScrollBarUI

public class MetalScrollBarUI extends BasicScrollBarUI

A UI delegate for the {@link JScrollBar} component.
Field Summary
protected MetalScrollButtondecreaseButton
The button that decreases the value in the scroll bar.
static StringFREE_STANDING_PROP
The name for the 'free standing' property.
protected MetalScrollButtonincreaseButton
The button that increases the value in the scroll bar.
protected booleanisFreeStanding
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 intscrollBarWidth
The scroll bar width.
Constructor Summary
MetalScrollBarUI()
Constructs a new instance of MetalScrollBarUI, with no specific initialisation.
Method Summary
protected JButtoncreateDecreaseButton(int orientation)
Creates a new button to use as the control at the lower end of the {@link JScrollBar}.
protected JButtoncreateIncreaseButton(int orientation)
Creates a new button to use as the control at the upper end of the {@link JScrollBar}.
protected PropertyChangeListenercreatePropertyChangeListener()
Creates a property change listener for the delegate to use.
static ComponentUIcreateUI(JComponent component)
Returns a new instance of MetalScrollBarUI.
protected DimensiongetMinimumThumbSize()
Returns the minimum thumb size.
DimensiongetPreferredSize(JComponent c)
Returns the preferredSize for the specified scroll bar.
protected voidinstallDefaults()
Installs the defaults.
protected voidpaintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
Paints the slider button of the ScrollBar.
protected voidpaintTrack(Graphics g, JComponent c, Rectangle trackBounds)
Paints the track for the scrollbar.

Field Detail

decreaseButton

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

FREE_STANDING_PROP

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

increaseButton

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

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.

scrollBarWidth

protected int scrollBarWidth
The scroll bar width.

Constructor Detail

MetalScrollBarUI

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

Method Detail

createDecreaseButton

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

Parameters: orientation the orientation of the button ({@link #NORTH}, {@link #SOUTH}, {@link #EAST} or {@link #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 {@link JScrollBar}. This method assigns the new button (an instance of {@link MetalScrollButton} to the {@link #increaseButton} field, and also returns the button. The button width is determined by the ScrollBar.width setting in the UI defaults.

Parameters: orientation the orientation of the button ({@link #NORTH}, {@link #SOUTH}, {@link #EAST} or {@link #WEST}).

Returns: The button.

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 {@link MetalLookAndFeel} that can handle the JScrollBar.isFreeStanding property.

Returns: A property change listener.

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

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.

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.

Parameters: c the scrollbar for which to calculate the preferred size

Returns: the preferredSize for the specified scroll bar

installDefaults

protected void installDefaults()
Installs the defaults.

paintThumb

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

Parameters: g the Graphics context to use c the JComponent on which we paint thumbBounds the rectangle that is the slider button

paintTrack

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

Parameters: g the graphics device. c the component. trackBounds the track bounds.