java.lang.Object java.awt.Component java.awt.Scrollbar
public class Scrollbar
The Scrollbar
class embodies a scroll bar, a familiar user-interface object. A scroll bar provides a convenient means for allowing a user to select from a range of values. The following three vertical scroll bars could be used as slider controls to pick the red, green, and blue components of a color:
Each scroll bar in this example could be created with code similar to the following:
redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255); add(redSlider);
Alternatively, a scroll bar can represent a range of values. For example, if a scroll bar is used for scrolling through text, the width of the "bubble" (also called the "thumb" or "scroll box") can be used to represent the amount of text that is visible. Here is an example of a scroll bar that represents a range:
The value range represented by the bubble in this example is the visible amount. The horizontal scroll bar in this example could be created with code like the following:
ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300); add(ranger);
Note that the actual maximum value of the scroll bar is the maximum
minus the visible amount
. In the previous example, because the maximum
is 300 and the visible amount
is 60, the actual maximum value is 240. The range of the scrollbar track is 0 - 300. The left side of the bubble indicates the value of the scroll bar.
Normally, the user changes the value of the scroll bar by making a gesture with the mouse. For example, the user can drag the scroll bar's bubble up and down, or click in the scroll bar's unit increment or block increment areas. Keyboard gestures can also be mapped to the scroll bar. By convention, the Page Up and Page Down keys are equivalent to clicking in the scroll bar's block increment and block decrement areas.
When the user changes the value of the scroll bar, the scroll bar receives an instance of AdjustmentEvent
. The scroll bar processes this event, passing it along to any registered listeners.
Any object that wishes to be notified of changes to the scroll bar's value should implement AdjustmentListener
, an interface defined in the package java.awt.event
. Listeners can be added and removed dynamically by calling the methods addAdjustmentListener
and removeAdjustmentListener
.
The AdjustmentEvent
class defines five types of adjustment event, listed here:
AdjustmentEvent.TRACK
is sent out when the user drags the scroll bar's bubble.AdjustmentEvent.UNIT_INCREMENT
is sent out when the user clicks in the left arrow of a horizontal scroll bar, or the top arrow of a vertical scroll bar, or makes the equivalent gesture from the keyboard.AdjustmentEvent.UNIT_DECREMENT
is sent out when the user clicks in the right arrow of a horizontal scroll bar, or the bottom arrow of a vertical scroll bar, or makes the equivalent gesture from the keyboard.AdjustmentEvent.BLOCK_INCREMENT
is sent out when the user clicks in the track, to the left of the bubble on a horizontal scroll bar, or above the bubble on a vertical scroll bar. By convention, the Page Up key is equivalent, if the user is using a keyboard that defines a Page Up key.AdjustmentEvent.BLOCK_DECREMENT
is sent out when the user clicks in the track, to the right of the bubble on a horizontal scroll bar, or below the bubble on a vertical scroll bar. By convention, the Page Down key is equivalent, if the user is using a keyboard that defines a Page Down key.The JDK 1.0 event system is supported for backwards compatibility, but its use with newer versions of the platform is discouraged. The five types of adjustment events introduced with JDK 1.1 correspond to the five event types that are associated with scroll bars in previous platform versions. The following list gives the adjustment event type, and the corresponding JDK 1.0 event type it replaces.
AdjustmentEvent.TRACK
replaces Event.SCROLL_ABSOLUTE
AdjustmentEvent.UNIT_INCREMENT
replaces Event.SCROLL_LINE_UP
AdjustmentEvent.UNIT_DECREMENT
replaces Event.SCROLL_LINE_DOWN
AdjustmentEvent.BLOCK_INCREMENT
replaces Event.SCROLL_PAGE_UP
AdjustmentEvent.BLOCK_DECREMENT
replaces Event.SCROLL_PAGE_DOWN
Note: We recommend using a Scrollbar
for value selection only. If you want to implement a scrollable component inside a container, we recommend you use a ScrollPane
. If you use a Scrollbar
for this purpose, you are likely to encounter issues with painting, key handling, sizing and positioning.
AdjustmentEvent
, AdjustmentListener
, Serialized Form
static int
HORIZONTAL
static int
VERTICAL
Scrollbar()
Scrollbar(int orientation)
Scrollbar(int orientation, int value, int visible, int minimum, int maximum)
void
addAdjustmentListener(AdjustmentListener l)
AdjustmentEvent
from this scroll bar. void
addNotify()
Scrollbar
's peer. AccessibleContext
getAccessibleContext()
AccessibleContext
associated with this Scrollbar
. AdjustmentListener[]
getAdjustmentListeners()
int
getBlockIncrement()
int
getLineIncrement()
getUnitIncrement()
. <T extends EventListener>
T[]
getListeners(Class<T> listenerType)
FooListener
s upon this Scrollbar
. int
getMaximum()
int
getMinimum()
int
getOrientation()
int
getPageIncrement()
getBlockIncrement()
. int
getUnitIncrement()
int
getValue()
boolean
getValueIsAdjusting()
int
getVisible()
getVisibleAmount()
. int
getVisibleAmount()
protected String
paramString()
Scrollbar
. protected void
processAdjustmentEvent(AdjustmentEvent e)
AdjustmentListener
objects. protected void
processEvent(AWTEvent e)
void
removeAdjustmentListener(AdjustmentListener l)
AdjustmentEvent
from this scroll bar. void
setBlockIncrement(int v)
void
setLineIncrement(int v)
setUnitIncrement(int)
. void
setMaximum(int newMaximum)
void
setMinimum(int newMinimum)
void
setOrientation(int orientation)
void
setPageIncrement(int v)
setBlockIncrement()
. void
setUnitIncrement(int v)
void
setValue(int newValue)
void
setValueIsAdjusting(boolean b)
valueIsAdjusting
property. void
setValues(int value, int visible, int minimum, int maximum)
value
, visibleAmount
, minimum
, and maximum
. void
setVisibleAmount(int newAmount)
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
HORIZONTAL
public static final int HORIZONTAL
public static final int VERTICAL
public Scrollbar() throws HeadlessException
Scrollbar.VERTICAL
value value which controls the location
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.
GraphicsEnvironment.isHeadless()
public Scrollbar(int orientation) throws HeadlessException
The orientation
argument must take one of the two values Scrollbar.HORIZONTAL
, or Scrollbar.VERTICAL
, indicating a horizontal or vertical scroll bar, respectively.
orientation
- indicates the orientation of the scroll bar
IllegalArgumentException
- when an illegal value for the orientation
argument is supplied
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.
GraphicsEnvironment.isHeadless()
public Scrollbar(int orientation, int value, int visible, int minimum, int maximum) throws HeadlessException
The orientation
argument must take one of the two values Scrollbar.HORIZONTAL
, or Scrollbar.VERTICAL
, indicating a horizontal or vertical scroll bar, respectively.
The parameters supplied to this constructor are subject to the constraints described in setValues(int, int, int, int)
.
orientation
- indicates the orientation of the scroll bar.
value
- the initial value of the scroll bar
visible
- the visible amount of the scroll bar, typically represented by the size of the bubble
minimum
- the minimum value of the scroll bar
maximum
- the maximum value of the scroll bar
IllegalArgumentException
- when an illegal value for the orientation
argument is supplied
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.
setValues(int, int, int, int)
, GraphicsEnvironment.isHeadless()
public void addNotify()
Scrollbar
's peer. The peer allows you to modify the appearance of the Scrollbar
without changing any of its functionality.
addNotify
in class Component
Component.isDisplayable()
, Component.removeNotify()
public int getOrientation()
getOrientation
in interface Adjustable
Scrollbar.HORIZONTAL
or Scrollbar.VERTICAL
setOrientation(int)
public void setOrientation(int orientation)
orientation
- the orientation of this scroll bar, either Scrollbar.HORIZONTAL
or Scrollbar.VERTICAL
IllegalArgumentException
- if the value supplied for orientation
is not a legal value
getOrientation()
public int getValue()
getValue
in interface Adjustable
getMinimum()
, getMaximum()
public void setValue(int newValue)
If the value supplied is less than the current minimum
or greater than the current maximum - visibleAmount
, then either minimum
or maximum - visibleAmount
is substituted, as appropriate.
Normally, a program should change a scroll bar's value only by calling setValues
. The setValues
method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.
Calling this method does not fire an AdjustmentEvent
.
setValue
in interface Adjustable
newValue
- the new value of the scroll bar
setValues(int, int, int, int)
, getValue()
, getMinimum()
, getMaximum()
public int getMinimum()
getMinimum
in interface Adjustable
getValue()
, getMaximum()
public void setMinimum(int newMinimum)
When setMinimum
is called, the minimum value is changed, and other values (including the maximum, the visible amount, and the current scroll bar value) are changed to be consistent with the new minimum.
Normally, a program should change a scroll bar's minimum value only by calling setValues
. The setValues
method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.
Note that setting the minimum value to Integer.MAX_VALUE
will result in the new minimum value being set to Integer.MAX_VALUE - 1
.
setMinimum
in interface Adjustable
newMinimum
- the new minimum value for this scroll bar
setValues(int, int, int, int)
, setMaximum(int)
public int getMaximum()
getMaximum
in interface Adjustable
getValue()
, getMinimum()
public void setMaximum(int newMaximum)
When setMaximum
is called, the maximum value is changed, and other values (including the minimum, the visible amount, and the current scroll bar value) are changed to be consistent with the new maximum.
Normally, a program should change a scroll bar's maximum value only by calling setValues
. The setValues
method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.
Note that setting the maximum value to Integer.MIN_VALUE
will result in the new maximum value being set to Integer.MIN_VALUE + 1
.
setMaximum
in interface Adjustable
newMaximum
- the new maximum value for this scroll bar
setValues(int, int, int, int)
, setMinimum(int)
public int getVisibleAmount()
When a scroll bar is used to select a range of values, the visible amount is used to represent the range of values that are currently visible. The size of the scroll bar's bubble (also called a thumb or scroll box), usually gives a visual representation of the relationship of the visible amount to the range of the scroll bar.
The scroll bar's bubble may not be displayed when it is not moveable (e.g. when it takes up the entire length of the scroll bar's track, or when the scroll bar is disabled). Whether the bubble is displayed or not will not affect the value returned by getVisibleAmount
.
getVisibleAmount
in interface Adjustable
setVisibleAmount(int)
@Deprecated public int getVisible()
getVisibleAmount()
.
public void setVisibleAmount(int newAmount)
When a scroll bar is used to select a range of values, the visible amount is used to represent the range of values that are currently visible. The size of the scroll bar's bubble (also called a thumb or scroll box), usually gives a visual representation of the relationship of the visible amount to the range of the scroll bar.
The scroll bar's bubble may not be displayed when it is not moveable (e.g. when it takes up the entire length of the scroll bar's track, or when the scroll bar is disabled). Whether the bubble is displayed or not will not affect the value returned by getVisibleAmount
.
If the visible amount supplied is less than one
or greater than the current maximum - minimum
, then either one
or maximum - minimum
is substituted, as appropriate.
Normally, a program should change a scroll bar's value only by calling setValues
. The setValues
method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.
setVisibleAmount
in interface Adjustable
newAmount
- the new visible amount
getVisibleAmount()
, setValues(int, int, int, int)
public void setUnitIncrement(int v)
The unit increment is the value that is added or subtracted when the user activates the unit increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event. The unit increment must be greater than zero. Attepts to set the unit increment to a value lower than 1 will result in a value of 1 being set.
setUnitIncrement
in interface Adjustable
v
- the amount by which to increment or decrement the scroll bar's value
getUnitIncrement()
@Deprecated public void setLineIncrement(int v)
setUnitIncrement(int)
.
public int getUnitIncrement()
The unit increment is the value that is added or subtracted when the user activates the unit increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event. The unit increment must be greater than zero.
getUnitIncrement
in interface Adjustable
setUnitIncrement(int)
@Deprecated public int getLineIncrement()
getUnitIncrement()
.
public void setBlockIncrement(int v)
The block increment is the value that is added or subtracted when the user activates the block increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event. The block increment must be greater than zero. Attepts to set the block increment to a value lower than 1 will result in a value of 1 being set.
setBlockIncrement
in interface Adjustable
v
- the amount by which to increment or decrement the scroll bar's value
getBlockIncrement()
@Deprecated public void setPageIncrement(int v)
setBlockIncrement()
.
public int getBlockIncrement()
The block increment is the value that is added or subtracted when the user activates the block increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event. The block increment must be greater than zero.
getBlockIncrement
in interface Adjustable
setBlockIncrement(int)
@Deprecated public int getPageIncrement()
getBlockIncrement()
.
public void setValues(int value, int visible, int minimum, int maximum)
value
, visibleAmount
, minimum
, and maximum
. If the values supplied for these properties are inconsistent or incorrect, they will be changed to ensure consistency.
This method simultaneously and synchronously sets the values of four scroll bar properties, assuring that the values of these properties are mutually consistent. It enforces the following constraints: maximum
must be greater than minimum
, maximum - minimum
must not be greater than Integer.MAX_VALUE
, visibleAmount
must be greater than zero. visibleAmount
must not be greater than maximum - minimum
, value
must not be less than minimum
, and value
must not be greater than maximum - visibleAmount
Calling this method does not fire an AdjustmentEvent
.
value
- is the position in the current window
visible
- is the visible amount of the scroll bar
minimum
- is the minimum value of the scroll bar
maximum
- is the maximum value of the scroll bar
setMinimum(int)
, setMaximum(int)
, setVisibleAmount(int)
, setValue(int)
public boolean getValueIsAdjusting()
valueIsAdjusting
property
setValueIsAdjusting(boolean)
public void setValueIsAdjusting(boolean b)
valueIsAdjusting
property.
b
- new adjustment-in-progress status
getValueIsAdjusting()
public void addAdjustmentListener(AdjustmentListener l)
AdjustmentEvent
from this scroll bar. If l is null
, no exception is thrown and no action is performed.
addAdjustmentListener
in interface Adjustable
l
- the adjustment listener
removeAdjustmentListener(java.awt.event.AdjustmentListener)
, getAdjustmentListeners()
, AdjustmentEvent
, AdjustmentListener
public void removeAdjustmentListener(AdjustmentListener l)
AdjustmentEvent
from this scroll bar. If l is null
, no exception is thrown and no action is performed.
removeAdjustmentListener
in interface Adjustable
l
- the adjustment listener
addAdjustmentListener(java.awt.event.AdjustmentListener)
, getAdjustmentListeners()
, AdjustmentEvent
, AdjustmentListener
public AdjustmentListener[] getAdjustmentListeners()
AdjustmentListener
s or an empty array if no adjustment listeners are currently registered
addAdjustmentListener(java.awt.event.AdjustmentListener)
, removeAdjustmentListener(java.awt.event.AdjustmentListener)
, AdjustmentEvent
, AdjustmentListener
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListener
s upon this Scrollbar
. FooListener
s are registered using the addFooListener
method.
You can specify the listenerType
argument with a class literal, such as FooListener.class
. For example, you can query a Scrollbar
c
for its mouse listeners with the following code:
MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));If no such listeners exist, this method returns an empty array.
getListeners
in class Component
listenerType
- the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
FooListener
s on this component, or an empty array if no such listeners have been added
ClassCastException
- if listenerType
doesn't specify a class or interface that implements java.util.EventListener
Component.getComponentListeners()
, Component.getFocusListeners()
, Component.getHierarchyListeners()
, Component.getHierarchyBoundsListeners()
, Component.getKeyListeners()
, Component.getMouseListeners()
, Component.getMouseMotionListeners()
, Component.getMouseWheelListeners()
, Component.getInputMethodListeners()
, Component.getPropertyChangeListeners()
protected void processEvent(AWTEvent e)
AdjustmentEvent
, it invokes the processAdjustmentEvent
method. Otherwise, it invokes its superclass's processEvent
method.
Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
processEvent
in class Component
e
- the event
AdjustmentEvent
, processAdjustmentEvent(java.awt.event.AdjustmentEvent)
protected void processAdjustmentEvent(AdjustmentEvent e)
AdjustmentListener
objects.
This method is not called unless adjustment events are enabled for this component. Adjustment events are enabled when one of the following occurs:
AdjustmentListener
object is registered via addAdjustmentListener
.enableEvents
.Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
e
- the adjustment event
AdjustmentEvent
, AdjustmentListener
, addAdjustmentListener(java.awt.event.AdjustmentListener)
, Component.enableEvents(long)
protected String paramString()
Scrollbar
. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null
.
paramString
in class Component
public AccessibleContext getAccessibleContext()
AccessibleContext
associated with this Scrollbar
. For scrollbars, the AccessibleContext
takes the form of an AccessibleAWTScrollBar
. A new AccessibleAWTScrollBar
instance is created if necessary.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class Component
AccessibleAWTScrollBar
that serves as the AccessibleContext
of this ScrollBar
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4