|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.ScrollPane
A container class which implements automatic horizontal and/or vertical scrolling for a single child component. The display policy for the scrollbars can be set to:
The state of the horizontal and vertical scrollbars is represented
by two ScrollPaneAdjustable
objects (one for each
dimension) which implement the Adjustable
interface.
The API provides methods to access those objects such that the
attributes on the Adjustable object (such as unitIncrement, value,
etc.) can be manipulated.
Certain adjustable properties (minimum, maximum, blockIncrement, and visibleAmount) are set internally by the scrollpane in accordance with the geometry of the scrollpane and its child and these should not be set by programs using the scrollpane.
If the scrollbar display policy is defined as "never", then the scrollpane can still be programmatically scrolled using the setScrollPosition() method and the scrollpane will move and clip the child's contents appropriately. This policy is useful if the program needs to create and manage its own adjustable controls.
The placement of the scrollbars is controlled by platform-specific properties set by the user outside of the program.
The initial size of this container is set to 100x100, but can be reset using setSize().
Scrolling with the wheel on a wheel-equipped mouse is enabled by default. This can be disabled using setWheelScrollingEnabled(). Wheel scrolling can be customized by setting the block and unit increment of the horizontal and vertical Adjustables.
Insets are used to define any space used by scrollbars and any borders created by the scroll pane. getInsets() can be used to get the current value for the insets. If the value of scrollbarsAlwaysVisible is false, then the value of the insets will change dynamically depending on whether the scrollbars are currently visible or not.
Nested Class Summary | |
protected class |
ScrollPane.AccessibleAWTScrollPane
This class implements accessibility support for the ScrollPane class. |
(package private) class |
ScrollPane.PeerFixer
|
Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer, Container.DropTargetEventTargetFilter, Container.EventTargetFilter, Container.MouseEventTargetFilter |
Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.AWTTreeLock, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
private static String |
base
|
private static boolean |
defaultWheelScroll
|
private ScrollPaneAdjustable |
hAdjustable
An adjustable horizontal scrollbar. |
private static int |
nameCounter
|
private int |
scrollbarDisplayPolicy
There are 3 ways in which a scroll bar can be displayed. |
static int |
SCROLLBARS_ALWAYS
Specifies that horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the scrollpane and child. |
static int |
SCROLLBARS_AS_NEEDED
Specifies that horizontal/vertical scrollbar should be shown only when the size of the child exceeds the size of the scrollpane in the horizontal/vertical dimension. |
static int |
SCROLLBARS_NEVER
Specifies that horizontal/vertical scrollbars should never be shown regardless of the respective sizes of the scrollpane and child. |
private static long |
serialVersionUID
|
private ScrollPaneAdjustable |
vAdjustable
An adjustable vertical scrollbar. |
private boolean |
wheelScrollingEnabled
Indicates whether or not scrolling should take place when a MouseWheelEvent is received. |
Fields inherited from class java.awt.Container |
component, containerListener, descendantsCount, INCLUDE_SELF, layoutMgr, listeningBoundsChildren, listeningChildren, ncomponents, SEARCH_HEAVYWEIGHTS |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
ScrollPane()
Create a new scrollpane container with a scrollbar display policy of "as needed". |
|
ScrollPane(int scrollbarDisplayPolicy)
Create a new scrollpane container. |
Method Summary | |
protected void |
addImpl(Component comp,
Object constraints,
int index)
Adds the specified component to this scroll pane container. |
void |
addNotify()
Creates the scroll pane's peer. |
(package private) void |
autoProcessMouseWheel(MouseWheelEvent e)
|
(package private) Dimension |
calculateChildSize()
Determine the size to allocate the child component. |
(package private) String |
constructComponentName()
Construct a name for this component. |
void |
doLayout()
Lays out this container by resizing its child to its preferred size. |
protected boolean |
eventTypeEnabled(int type)
If wheel scrolling is enabled, we return true for MouseWheelEvents |
javax.accessibility.AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this ScrollPane. |
Adjustable |
getHAdjustable()
Returns the ScrollPaneAdjustable object which
represents the state of the horizontal scrollbar.
|
int |
getHScrollbarHeight()
Returns the height that would be occupied by a horizontal scrollbar, which is independent of whether it is currently displayed by the scroll pane or not. |
int |
getScrollbarDisplayPolicy()
Returns the display policy for the scrollbars. |
Point |
getScrollPosition()
Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port. |
Adjustable |
getVAdjustable()
Returns the ScrollPaneAdjustable object which
represents the state of the vertical scrollbar.
|
Dimension |
getViewportSize()
Returns the current size of the scroll pane's view port. |
int |
getVScrollbarWidth()
Returns the width that would be occupied by a vertical scrollbar, which is independent of whether it is currently displayed by the scroll pane or not. |
private static void |
initIDs()
Initialize JNI field and method IDs |
boolean |
isWheelScrollingEnabled()
Indicates whether or not scrolling will take place in response to the mouse wheel. |
void |
layout()
Deprecated. As of JDK version 1.1, replaced by doLayout() . |
String |
paramString()
Returns a string representing the state of this ScrollPane . |
void |
printComponents(Graphics g)
Prints the component in this scroll pane. |
protected void |
processMouseWheelEvent(MouseWheelEvent e)
Process mouse wheel events that are delivered to this ScrollPane by scrolling an appropriate amount.
|
private void |
readObject(ObjectInputStream s)
Reads default serializable fields to stream. |
void |
setLayout(LayoutManager mgr)
Sets the layout manager for this container. |
void |
setScrollPosition(int x,
int y)
Scrolls to the specified position within the child component. |
void |
setScrollPosition(Point p)
Scrolls to the specified position within the child component. |
void |
setWheelScrollingEnabled(boolean handleWheel)
Enables/disables scrolling in response to movement of the mouse wheel. |
private void |
writeObject(ObjectOutputStream s)
Writes default serializable fields to stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int SCROLLBARS_AS_NEEDED
public static final int SCROLLBARS_ALWAYS
public static final int SCROLLBARS_NEVER
private int scrollbarDisplayPolicy
getScrollbarDisplayPolicy()
private ScrollPaneAdjustable vAdjustable
Adjustable
methods, namely:
setMinimum()
, setMaximum()
,
setVisibleAmount()
.
getVAdjustable()
private ScrollPaneAdjustable hAdjustable
Adjustable
methods, namely:
setMinimum()
, setMaximum()
,
setVisibleAmount()
.
getHAdjustable()
private static final String base
private static int nameCounter
private static final boolean defaultWheelScroll
private boolean wheelScrollingEnabled
private static final long serialVersionUID
Constructor Detail |
public ScrollPane() throws HeadlessException
HeadlessException
- if GraphicsEnvironment.isHeadless()
returns trueGraphicsEnvironment.isHeadless()
public ScrollPane(int scrollbarDisplayPolicy) throws HeadlessException
scrollbarDisplayPolicy
- policy for when scrollbars should be shown
IllegalArgumentException
- if the specified scrollbar
display policy is invalid
HeadlessException
- if GraphicsEnvironment.isHeadless()
returns trueGraphicsEnvironment.isHeadless()
Method Detail |
private static void initIDs()
String constructComponentName()
constructComponentName
in class Component
protected final void addImpl(Component comp, Object constraints, int index)
addImpl
in class Container
comp
- the component to be addedconstraints
- not applicableindex
- position of child component (must be <= 0)Container.add(Component)
,
Container.add(Component, int)
,
Container.add(Component, java.lang.Object)
,
LayoutManager
,
LayoutManager2
public int getScrollbarDisplayPolicy()
public Dimension getViewportSize()
public int getHScrollbarHeight()
public int getVScrollbarWidth()
public Adjustable getVAdjustable()
ScrollPaneAdjustable
object which
represents the state of the vertical scrollbar.
The declared return type of this method is
Adjustable
to maintain backward compatibility.
ScrollPaneAdjustable
public Adjustable getHAdjustable()
ScrollPaneAdjustable
object which
represents the state of the horizontal scrollbar.
The declared return type of this method is
Adjustable
to maintain backward compatibility.
ScrollPaneAdjustable
public void setScrollPosition(int x, int y)
x
- the x position to scroll toy
- the y position to scroll to
NullPointerException
- if the scrollpane does not contain
a childpublic void setScrollPosition(Point p)
p
- the Point representing the position to scroll topublic Point getScrollPosition()
NullPointerException
- if the scrollpane does not contain
a childpublic final void setLayout(LayoutManager mgr)
setLayout
in class Container
mgr
- the specified layout managerContainer.doLayout()
,
Container.getLayout()
public void doLayout()
doLayout
in class Container
Component.validate()
Dimension calculateChildSize()
public void layout()
doLayout()
.
layout
in class Container
public void printComponents(Graphics g)
printComponents
in class Container
g
- the specified Graphics windowComponent.print(java.awt.Graphics)
,
Component.printAll(java.awt.Graphics)
public void addNotify()
addNotify
in class Container
Component.isDisplayable()
,
Container.removeNotify()
public String paramString()
ScrollPane
. 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 Container
void autoProcessMouseWheel(MouseWheelEvent e)
autoProcessMouseWheel
in class Component
protected void processMouseWheelEvent(MouseWheelEvent e)
ScrollPane
by scrolling an appropriate amount.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
processMouseWheelEvent
in class Component
e
- the mouse wheel eventMouseWheelEvent
,
MouseWheelListener
,
Component.addMouseWheelListener(java.awt.event.MouseWheelListener)
,
Component.enableEvents(long)
protected boolean eventTypeEnabled(int type)
eventTypeEnabled
in class Component
public void setWheelScrollingEnabled(boolean handleWheel)
handleWheel
- true
if scrolling should be done
automatically for a MouseWheelEvent,
false
otherwise.isWheelScrollingEnabled()
,
MouseWheelEvent
,
MouseWheelListener
public boolean isWheelScrollingEnabled()
setWheelScrollingEnabled(boolean)
private void writeObject(ObjectOutputStream s) throws IOException
IOException
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException
HeadlessException
- if
GraphicsEnvironment.isHeadless()
returns
true
ClassNotFoundException
IOException
GraphicsEnvironment.isHeadless()
public javax.accessibility.AccessibleContext getAccessibleContext()
getAccessibleContext
in interface javax.accessibility.Accessible
getAccessibleContext
in class Component
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |