Fields Summary |
---|
public static final int | SCROLLBARS_AS_NEEDEDSpecifies 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. |
public static final int | SCROLLBARS_ALWAYSSpecifies that horizontal/vertical scrollbars should always be
shown regardless of the respective sizes of the scrollpane and child. |
public static final int | SCROLLBARS_NEVERSpecifies that horizontal/vertical scrollbars should never be shown
regardless of the respective sizes of the scrollpane and child. |
private int | scrollbarDisplayPolicyThere are 3 ways in which a scroll bar can be displayed.
This integer will represent one of these 3 displays -
(SCROLLBARS_ALWAYS, SCROLLBARS_AS_NEEDED, SCROLLBARS_NEVER) |
private ScrollPaneAdjustable | vAdjustableAn adjustable vertical scrollbar.
It is important to note that you must NOT call 3
Adjustable methods, namely:
setMinimum() , setMaximum() ,
setVisibleAmount() . |
private ScrollPaneAdjustable | hAdjustableAn adjustable horizontal scrollbar.
It is important to note that you must NOT call 3
Adjustable methods, namely:
setMinimum() , setMaximum() ,
setVisibleAmount() . |
private static final String | base |
private static int | nameCounter |
private static final boolean | defaultWheelScroll |
private boolean | wheelScrollingEnabledIndicates whether or not scrolling should take place when a
MouseWheelEvent is received. |
private static final long | serialVersionUID |
Methods Summary |
---|
protected final void | addImpl(java.awt.Component comp, java.lang.Object constraints, int index)Adds the specified component to this scroll pane container.
If the scroll pane has an existing child component, that
component is removed and the new one is added.
synchronized (getTreeLock()) {
if (getComponentCount() > 0) {
remove(0);
}
if (index > 0) {
throw new IllegalArgumentException("position greater than 0");
}
if (!SunToolkit.isLightweightOrUnknown(comp)) {
super.addImpl(comp, constraints, index);
} else {
addToPanel(comp, constraints, index);
}
}
|
public void | addNotify()Creates the scroll pane's peer.
synchronized (getTreeLock()) {
int vAdjustableValue = 0;
int hAdjustableValue = 0;
// Bug 4124460. Save the current adjustable values,
// so they can be restored after addnotify. Set the
// adjustables to 0, to prevent crashes for possible
// negative values.
if (getComponentCount() > 0) {
vAdjustableValue = vAdjustable.getValue();
hAdjustableValue = hAdjustable.getValue();
vAdjustable.setValue(0);
hAdjustable.setValue(0);
}
if (peer == null)
peer = getToolkit().createScrollPane(this);
super.addNotify();
// Bug 4124460. Restore the adjustable values.
if (getComponentCount() > 0) {
vAdjustable.setValue(vAdjustableValue);
hAdjustable.setValue(hAdjustableValue);
}
}
|
private void | addToPanel(java.awt.Component comp, java.lang.Object constraints, int index)
Panel child = new Panel();
child.setLayout(new BorderLayout());
child.add(comp);
super.addImpl(child, constraints, index);
validate();
|
void | autoProcessMouseWheel(java.awt.event.MouseWheelEvent e)
processMouseWheelEvent(e);
|
java.awt.Dimension | calculateChildSize()Determine the size to allocate the child component.
If the viewport area is bigger than the childs
preferred size then the child is allocated enough
to fill the viewport, otherwise the child is given
it's preferred size.
//
// calculate the view size, accounting for border but not scrollbars
// - don't use right/bottom insets since they vary depending
// on whether or not scrollbars were displayed on last resize
//
Dimension size = getSize();
Insets insets = getInsets();
int viewWidth = size.width - insets.left*2;
int viewHeight = size.height - insets.top*2;
//
// determine whether or not horz or vert scrollbars will be displayed
//
boolean vbarOn;
boolean hbarOn;
Component child = getComponent(0);
Dimension childSize = new Dimension(child.getPreferredSize());
if (scrollbarDisplayPolicy == SCROLLBARS_AS_NEEDED) {
vbarOn = childSize.height > viewHeight;
hbarOn = childSize.width > viewWidth;
} else if (scrollbarDisplayPolicy == SCROLLBARS_ALWAYS) {
vbarOn = hbarOn = true;
} else { // SCROLLBARS_NEVER
vbarOn = hbarOn = false;
}
//
// adjust predicted view size to account for scrollbars
//
int vbarWidth = getVScrollbarWidth();
int hbarHeight = getHScrollbarHeight();
if (vbarOn) {
viewWidth -= vbarWidth;
}
if(hbarOn) {
viewHeight -= hbarHeight;
}
//
// if child is smaller than view, size it up
//
if (childSize.width < viewWidth) {
childSize.width = viewWidth;
}
if (childSize.height < viewHeight) {
childSize.height = viewHeight;
}
return childSize;
|
java.lang.String | constructComponentName()Construct a name for this component. Called by getName() when the
name is null.
synchronized (getClass()) {
return base + nameCounter++;
}
|
public void | doLayout()Lays out this container by resizing its child to its preferred size.
If the new preferred size of the child causes the current scroll
position to be invalid, the scroll position is set to the closest
valid position.
layout();
|
protected boolean | eventTypeEnabled(int type)If wheel scrolling is enabled, we return true for MouseWheelEvents
if (type == MouseEvent.MOUSE_WHEEL && isWheelScrollingEnabled()) {
return true;
}
else {
return super.eventTypeEnabled(type);
}
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this ScrollPane.
For scroll panes, the AccessibleContext takes the form of an
AccessibleAWTScrollPane.
A new AccessibleAWTScrollPane instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTScrollPane();
}
return accessibleContext;
|
public java.awt.Adjustable | getHAdjustable()Returns the ScrollPaneAdjustable object which
represents the state of the horizontal scrollbar.
The declared return type of this method is
Adjustable to maintain backward compatibility.
return hAdjustable;
|
public 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 h = 0;
if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
ScrollPanePeer peer = (ScrollPanePeer)this.peer;
if (peer != null) {
h = peer.getHScrollbarHeight();
}
}
return h;
|
public java.awt.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.
This is a convenience method which interfaces with the adjustable
objects which represent the state of the scrollbars.
if (ncomponents <= 0) {
throw new NullPointerException("child is null");
}
return new Point(hAdjustable.getValue(), vAdjustable.getValue());
|
public int | getScrollbarDisplayPolicy()Returns the display policy for the scrollbars.
return scrollbarDisplayPolicy;
|
public java.awt.Adjustable | getVAdjustable()Returns the ScrollPaneAdjustable object which
represents the state of the vertical scrollbar.
The declared return type of this method is
Adjustable to maintain backward compatibility.
return vAdjustable;
|
public 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.
int w = 0;
if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
ScrollPanePeer peer = (ScrollPanePeer)this.peer;
if (peer != null) {
w = peer.getVScrollbarWidth();
}
}
return w;
|
public java.awt.Dimension | getViewportSize()Returns the current size of the scroll pane's view port.
Insets i = getInsets();
return new Dimension(width - i.right - i.left,
height - i.top - i.bottom);
|
private static native void | initIDs()Initialize JNI field and method IDs
|
public boolean | isWheelScrollingEnabled()Indicates whether or not scrolling will take place in response to
the mouse wheel. Wheel scrolling is enabled by default.
return wheelScrollingEnabled;
|
public void | layout()
if (ncomponents > 0) {
Component c = getComponent(0);
Point p = getScrollPosition();
Dimension cs = calculateChildSize();
Dimension vs = getViewportSize();
Insets i = getInsets();
c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height);
ScrollPanePeer peer = (ScrollPanePeer)this.peer;
if (peer != null) {
peer.childResized(cs.width, cs.height);
}
// update adjustables... the viewport size may have changed
// with the scrollbars coming or going so the viewport size
// is updated before the adjustables.
vs = getViewportSize();
hAdjustable.setSpan(0, cs.width, vs.width);
vAdjustable.setSpan(0, cs.height, vs.height);
}
|
public java.lang.String | paramString()Returns a string representing the state of this
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 .
String sdpStr;
switch (scrollbarDisplayPolicy) {
case SCROLLBARS_AS_NEEDED:
sdpStr = "as-needed";
break;
case SCROLLBARS_ALWAYS:
sdpStr = "always";
break;
case SCROLLBARS_NEVER:
sdpStr = "never";
break;
default:
sdpStr = "invalid display policy";
}
Point p = ncomponents > 0? getScrollPosition() : new Point(0,0);
Insets i = getInsets();
return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
",ScrollbarDisplayPolicy="+sdpStr+
",wheelScrollingEnabled="+isWheelScrollingEnabled();
|
public void | printComponents(java.awt.Graphics g)Prints the component in this scroll pane.
if (ncomponents > 0) {
Component c = component[0];
Point p = c.getLocation();
Dimension vs = getViewportSize();
Insets i = getInsets();
Graphics cg = g.create();
try {
cg.clipRect(i.left, i.top, vs.width, vs.height);
cg.translate(p.x, p.y);
c.printAll(cg);
} finally {
cg.dispose();
}
}
|
protected void | processMouseWheelEvent(java.awt.event.MouseWheelEvent e)Process mouse wheel events that are delivered to this
ScrollPane by scrolling an appropriate amount.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
if (isWheelScrollingEnabled()) {
ScrollPaneWheelScroller.handleWheelScrolling(this, e);
e.consume();
}
super.processMouseWheelEvent(e);
|
private void | readObject(java.io.ObjectInputStream s)Reads default serializable fields to stream.
GraphicsEnvironment.checkHeadless();
// 4352819: Gotcha! Cannot use s.defaultReadObject here and
// then continue with reading optional data. Use GetField instead.
ObjectInputStream.GetField f = s.readFields();
// Old fields
scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
SCROLLBARS_AS_NEEDED);
hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);
// Since 1.4
wheelScrollingEnabled = f.get("wheelScrollingEnabled",
defaultWheelScroll);
// // Note to future maintainers
// if (f.defaulted("wheelScrollingEnabled")) {
// // We are reading pre-1.4 stream that doesn't have
// // optional data, not even the TC_ENDBLOCKDATA marker.
// // Reading anything after this point is unsafe as we will
// // read unrelated objects further down the stream (4352819).
// }
// else {
// // Reading data from 1.4 or later, it's ok to try to read
// // optional data as OptionalDataException with eof == true
// // will be correctly reported
// }
|
public final void | setLayout(java.awt.LayoutManager mgr)Sets the layout manager for this container. This method is
overridden to prevent the layout mgr from being set.
throw new AWTError("ScrollPane controls layout");
|
public void | setScrollPosition(int x, int y)Scrolls to the specified position within the child component.
A call to this method is only valid if the scroll pane contains
a child. Specifying a position outside of the legal scrolling bounds
of the child will scroll to the closest legal position.
Legal bounds are defined to be the rectangle:
x = 0, y = 0, width = (child width - view port width),
height = (child height - view port height).
This is a convenience method which interfaces with the Adjustable
objects which represent the state of the scrollbars.
synchronized (getTreeLock()) {
if (ncomponents <= 0) {
throw new NullPointerException("child is null");
}
hAdjustable.setValue(x);
vAdjustable.setValue(y);
}
|
public void | setScrollPosition(java.awt.Point p)Scrolls to the specified position within the child component.
A call to this method is only valid if the scroll pane contains
a child and the specified position is within legal scrolling bounds
of the child. Specifying a position outside of the legal scrolling
bounds of the child will scroll to the closest legal position.
Legal bounds are defined to be the rectangle:
x = 0, y = 0, width = (child width - view port width),
height = (child height - view port height).
This is a convenience method which interfaces with the Adjustable
objects which represent the state of the scrollbars.
setScrollPosition(p.x, p.y);
|
public void | setWheelScrollingEnabled(boolean handleWheel)Enables/disables scrolling in response to movement of the mouse wheel.
Wheel scrolling is enabled by default.
wheelScrollingEnabled = handleWheel;
|
private void | writeObject(java.io.ObjectOutputStream s)Writes default serializable fields to stream.
// 4352819: We only need this degenerate writeObject to make
// it safe for future versions of this class to write optional
// data to the stream.
s.defaultWriteObject();
|