Methods Summary |
---|
public javax.swing.JScrollBar | createHorizontalScrollBar()Returns a JScrollPane.ScrollBar by default.
Subclasses may override this method to force ScrollPaneUI
implementations to use a JScrollBar subclass.
Used by ScrollPaneUI implementations to
create the horizontal scrollbar.
return new ScrollBar(JScrollBar.HORIZONTAL);
|
public javax.swing.JScrollBar | createVerticalScrollBar()Returns a JScrollPane.ScrollBar by default. Subclasses
may override this method to force ScrollPaneUI
implementations to use a JScrollBar subclass.
Used by ScrollPaneUI implementations to create the
vertical scrollbar.
return new ScrollBar(JScrollBar.VERTICAL);
|
protected javax.swing.JViewport | createViewport()Returns a new JViewport by default.
Used to create the
viewport (as needed) in setViewportView ,
setRowHeaderView , and setColumnHeaderView .
Subclasses may override this method to return a subclass of
JViewport .
return new JViewport();
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this JScrollPane.
For scroll panes, the AccessibleContext takes the form of an
AccessibleJScrollPane.
A new AccessibleJScrollPane instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJScrollPane();
}
return accessibleContext;
|
public javax.swing.JViewport | getColumnHeader()Returns the column header.
return columnHeader;
|
public java.awt.Component | getCorner(java.lang.String key)Returns the component at the specified corner. The
key value specifying the corner is one of:
- JScrollPane.LOWER_LEFT_CORNER
- JScrollPane.LOWER_RIGHT_CORNER
- JScrollPane.UPPER_LEFT_CORNER
- JScrollPane.UPPER_RIGHT_CORNER
- JScrollPane.LOWER_LEADING_CORNER
- JScrollPane.LOWER_TRAILING_CORNER
- JScrollPane.UPPER_LEADING_CORNER
- JScrollPane.UPPER_TRAILING_CORNER
boolean isLeftToRight = getComponentOrientation().isLeftToRight();
if (key.equals(LOWER_LEADING_CORNER)) {
key = isLeftToRight ? LOWER_LEFT_CORNER : LOWER_RIGHT_CORNER;
} else if (key.equals(LOWER_TRAILING_CORNER)) {
key = isLeftToRight ? LOWER_RIGHT_CORNER : LOWER_LEFT_CORNER;
} else if (key.equals(UPPER_LEADING_CORNER)) {
key = isLeftToRight ? UPPER_LEFT_CORNER : UPPER_RIGHT_CORNER;
} else if (key.equals(UPPER_TRAILING_CORNER)) {
key = isLeftToRight ? UPPER_RIGHT_CORNER : UPPER_LEFT_CORNER;
}
if (key.equals(LOWER_LEFT_CORNER)) {
return lowerLeft;
}
else if (key.equals(LOWER_RIGHT_CORNER)) {
return lowerRight;
}
else if (key.equals(UPPER_LEFT_CORNER)) {
return upperLeft;
}
else if (key.equals(UPPER_RIGHT_CORNER)) {
return upperRight;
}
else {
return null;
}
|
public javax.swing.JScrollBar | getHorizontalScrollBar()Returns the horizontal scroll bar that controls the viewport's
horizontal view position.
return horizontalScrollBar;
|
public int | getHorizontalScrollBarPolicy()Returns the horizontal scroll bar policy value.
return horizontalScrollBarPolicy;
|
public javax.swing.JViewport | getRowHeader()Returns the row header.
return rowHeader;
|
public javax.swing.plaf.ScrollPaneUI | getUI()Returns the look and feel (L&F) object that renders this component.
return (ScrollPaneUI)ui;
|
public java.lang.String | getUIClassID()Returns the suffix used to construct the name of the L&F class used to
render this component.
return uiClassID;
|
public javax.swing.JScrollBar | getVerticalScrollBar()Returns the vertical scroll bar that controls the viewports
vertical view position.
return verticalScrollBar;
|
public int | getVerticalScrollBarPolicy()Returns the vertical scroll bar policy value.
return verticalScrollBarPolicy;
|
public javax.swing.JViewport | getViewport()Returns the current JViewport .
return viewport;
|
public javax.swing.border.Border | getViewportBorder()Returns the Border object that surrounds the viewport.
return viewportBorder;
|
public java.awt.Rectangle | getViewportBorderBounds()Returns the bounds of the viewport's border.
Rectangle borderR = new Rectangle(getSize());
Insets insets = getInsets();
borderR.x = insets.left;
borderR.y = insets.top;
borderR.width -= insets.left + insets.right;
borderR.height -= insets.top + insets.bottom;
boolean leftToRight = SwingUtilities.isLeftToRight(this);
/* If there's a visible column header remove the space it
* needs from the top of borderR.
*/
JViewport colHead = getColumnHeader();
if ((colHead != null) && (colHead.isVisible())) {
int colHeadHeight = colHead.getHeight();
borderR.y += colHeadHeight;
borderR.height -= colHeadHeight;
}
/* If there's a visible row header remove the space it needs
* from the left of borderR.
*/
JViewport rowHead = getRowHeader();
if ((rowHead != null) && (rowHead.isVisible())) {
int rowHeadWidth = rowHead.getWidth();
if ( leftToRight ) {
borderR.x += rowHeadWidth;
}
borderR.width -= rowHeadWidth;
}
/* If there's a visible vertical scrollbar remove the space it needs
* from the width of borderR.
*/
JScrollBar vsb = getVerticalScrollBar();
if ((vsb != null) && (vsb.isVisible())) {
int vsbWidth = vsb.getWidth();
if ( !leftToRight ) {
borderR.x += vsbWidth;
}
borderR.width -= vsbWidth;
}
/* If there's a visible horizontal scrollbar remove the space it needs
* from the height of borderR.
*/
JScrollBar hsb = getHorizontalScrollBar();
if ((hsb != null) && (hsb.isVisible())) {
borderR.height -= hsb.getHeight();
}
return borderR;
|
public boolean | isValidateRoot()Overridden to return true so that any calls to revalidate
on any descendants of this JScrollPane will cause the
entire tree beginning with this JScrollPane to be
validated.
return true;
|
public boolean | isWheelScrollingEnabled()Indicates whether or not scrolling will take place in response to the
mouse wheel. Wheel scrolling is enabled by default.return wheelScrollState;
|
protected java.lang.String | paramString()Returns a string representation of this JScrollPane .
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 viewportBorderString = (viewportBorder != null ?
viewportBorder.toString() : "");
String viewportString = (viewport != null ?
viewport.toString() : "");
String verticalScrollBarPolicyString;
if (verticalScrollBarPolicy == VERTICAL_SCROLLBAR_AS_NEEDED) {
verticalScrollBarPolicyString = "VERTICAL_SCROLLBAR_AS_NEEDED";
} else if (verticalScrollBarPolicy == VERTICAL_SCROLLBAR_NEVER) {
verticalScrollBarPolicyString = "VERTICAL_SCROLLBAR_NEVER";
} else if (verticalScrollBarPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
verticalScrollBarPolicyString = "VERTICAL_SCROLLBAR_ALWAYS";
} else verticalScrollBarPolicyString = "";
String horizontalScrollBarPolicyString;
if (horizontalScrollBarPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED) {
horizontalScrollBarPolicyString = "HORIZONTAL_SCROLLBAR_AS_NEEDED";
} else if (horizontalScrollBarPolicy == HORIZONTAL_SCROLLBAR_NEVER) {
horizontalScrollBarPolicyString = "HORIZONTAL_SCROLLBAR_NEVER";
} else if (horizontalScrollBarPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
horizontalScrollBarPolicyString = "HORIZONTAL_SCROLLBAR_ALWAYS";
} else horizontalScrollBarPolicyString = "";
String horizontalScrollBarString = (horizontalScrollBar != null ?
horizontalScrollBar.toString()
: "");
String verticalScrollBarString = (verticalScrollBar != null ?
verticalScrollBar.toString() : "");
String columnHeaderString = (columnHeader != null ?
columnHeader.toString() : "");
String rowHeaderString = (rowHeader != null ?
rowHeader.toString() : "");
String lowerLeftString = (lowerLeft != null ?
lowerLeft.toString() : "");
String lowerRightString = (lowerRight != null ?
lowerRight.toString() : "");
String upperLeftString = (upperLeft != null ?
upperLeft.toString() : "");
String upperRightString = (upperRight != null ?
upperRight.toString() : "");
return super.paramString() +
",columnHeader=" + columnHeaderString +
",horizontalScrollBar=" + horizontalScrollBarString +
",horizontalScrollBarPolicy=" + horizontalScrollBarPolicyString +
",lowerLeft=" + lowerLeftString +
",lowerRight=" + lowerRightString +
",rowHeader=" + rowHeaderString +
",upperLeft=" + upperLeftString +
",upperRight=" + upperRightString +
",verticalScrollBar=" + verticalScrollBarString +
",verticalScrollBarPolicy=" + verticalScrollBarPolicyString +
",viewport=" + viewportString +
",viewportBorder=" + viewportBorderString;
|
public void | setColumnHeader(javax.swing.JViewport columnHeader)Removes the old columnHeader, if it exists. If the new columnHeader
isn't null , sync the x coordinate of the its viewPosition
with the viewport (if there is one) and then add it to the scrollpane.
Most applications will find it more convenient to use
setRowHeaderView
to add a row header component and its viewport to the scrollpane.
JViewport old = getColumnHeader();
this.columnHeader = columnHeader;
if (columnHeader != null) {
add(columnHeader, COLUMN_HEADER);
}
else if (old != null) {
remove(old);
}
firePropertyChange("columnHeader", old, columnHeader);
revalidate();
repaint();
|
public void | setColumnHeaderView(java.awt.Component view)Creates a column-header viewport if necessary, sets
its view, and then adds the column-header viewport
to the scrollpane. For example:
JScrollPane scrollpane = new JScrollPane();
scrollpane.setViewportView(myBigComponentToScroll);
scrollpane.setColumnHeaderView(myBigComponentsColumnHeader);
if (getColumnHeader() == null) {
setColumnHeader(createViewport());
}
getColumnHeader().setView(view);
|
public void | setComponentOrientation(java.awt.ComponentOrientation co)Sets the orientation for the vertical and horizontal
scrollbars as determined by the
ComponentOrientation argument.
super.setComponentOrientation( co );
if( verticalScrollBar != null )
verticalScrollBar.setComponentOrientation( co );
if( horizontalScrollBar != null )
horizontalScrollBar.setComponentOrientation( co );
|
public void | setCorner(java.lang.String key, java.awt.Component corner)Adds a child that will appear in one of the scroll panes
corners, if there's room. For example with both scrollbars
showing (on the right and bottom edges of the scrollpane)
the lower left corner component will be shown in the space
between ends of the two scrollbars. Legal values for
the key are:
- JScrollPane.LOWER_LEFT_CORNER
- JScrollPane.LOWER_RIGHT_CORNER
- JScrollPane.UPPER_LEFT_CORNER
- JScrollPane.UPPER_RIGHT_CORNER
- JScrollPane.LOWER_LEADING_CORNER
- JScrollPane.LOWER_TRAILING_CORNER
- JScrollPane.UPPER_LEADING_CORNER
- JScrollPane.UPPER_TRAILING_CORNER
Although "corner" doesn't match any beans property
signature, PropertyChange events are generated with the
property name set to the corner key.
Component old;
boolean isLeftToRight = getComponentOrientation().isLeftToRight();
if (key.equals(LOWER_LEADING_CORNER)) {
key = isLeftToRight ? LOWER_LEFT_CORNER : LOWER_RIGHT_CORNER;
} else if (key.equals(LOWER_TRAILING_CORNER)) {
key = isLeftToRight ? LOWER_RIGHT_CORNER : LOWER_LEFT_CORNER;
} else if (key.equals(UPPER_LEADING_CORNER)) {
key = isLeftToRight ? UPPER_LEFT_CORNER : UPPER_RIGHT_CORNER;
} else if (key.equals(UPPER_TRAILING_CORNER)) {
key = isLeftToRight ? UPPER_RIGHT_CORNER : UPPER_LEFT_CORNER;
}
if (key.equals(LOWER_LEFT_CORNER)) {
old = lowerLeft;
lowerLeft = corner;
}
else if (key.equals(LOWER_RIGHT_CORNER)) {
old = lowerRight;
lowerRight = corner;
}
else if (key.equals(UPPER_LEFT_CORNER)) {
old = upperLeft;
upperLeft = corner;
}
else if (key.equals(UPPER_RIGHT_CORNER)) {
old = upperRight;
upperRight = corner;
}
else {
throw new IllegalArgumentException("invalid corner key");
}
if (old != null) {
remove(old);
}
if (corner != null) {
add(corner, key);
}
firePropertyChange(key, old, corner);
revalidate();
repaint();
|
public void | setHorizontalScrollBar(javax.swing.JScrollBar horizontalScrollBar)Adds the scrollbar that controls the viewport's horizontal view
position to the scrollpane.
This is usually unnecessary, as JScrollPane creates
horizontal and vertical scrollbars by default.
JScrollBar old = getHorizontalScrollBar();
this.horizontalScrollBar = horizontalScrollBar;
if (horizontalScrollBar != null) {
add(horizontalScrollBar, HORIZONTAL_SCROLLBAR);
}
else if (old != null) {
remove(old);
}
firePropertyChange("horizontalScrollBar", old, horizontalScrollBar);
revalidate();
repaint();
|
public void | setHorizontalScrollBarPolicy(int policy)Determines when the horizontal scrollbar appears in the scrollpane.
The options are:
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
switch (policy) {
case HORIZONTAL_SCROLLBAR_AS_NEEDED:
case HORIZONTAL_SCROLLBAR_NEVER:
case HORIZONTAL_SCROLLBAR_ALWAYS:
break;
default:
throw new IllegalArgumentException("invalid horizontalScrollBarPolicy");
}
int old = horizontalScrollBarPolicy;
horizontalScrollBarPolicy = policy;
firePropertyChange("horizontalScrollBarPolicy", old, policy);
revalidate();
repaint();
|
public void | setLayout(java.awt.LayoutManager layout)Sets the layout manager for this JScrollPane .
This method overrides setLayout in
java.awt.Container to ensure that only
LayoutManager s which
are subclasses of ScrollPaneLayout can be used in a
JScrollPane . If layout is non-null, this
will invoke syncWithScrollPane on it.
if (layout instanceof ScrollPaneLayout) {
super.setLayout(layout);
((ScrollPaneLayout)layout).syncWithScrollPane(this);
}
else if (layout == null) {
super.setLayout(layout);
}
else {
String s = "layout of JScrollPane must be a ScrollPaneLayout";
throw new ClassCastException(s);
}
|
public void | setRowHeader(javax.swing.JViewport rowHeader)Removes the old rowHeader, if it exists. If the new rowHeader
isn't null , syncs the y coordinate of its
viewPosition with
the viewport (if there is one) and then adds it to the scrollpane.
Most applications will find it more convenient to use
setRowHeaderView
to add a row header component and its viewport to the scrollpane.
JViewport old = getRowHeader();
this.rowHeader = rowHeader;
if (rowHeader != null) {
add(rowHeader, ROW_HEADER);
}
else if (old != null) {
remove(old);
}
firePropertyChange("rowHeader", old, rowHeader);
revalidate();
repaint();
|
public void | setRowHeaderView(java.awt.Component view)Creates a row-header viewport if necessary, sets
its view and then adds the row-header viewport
to the scrollpane. For example:
JScrollPane scrollpane = new JScrollPane();
scrollpane.setViewportView(myBigComponentToScroll);
scrollpane.setRowHeaderView(myBigComponentsRowHeader);
if (getRowHeader() == null) {
setRowHeader(createViewport());
}
getRowHeader().setView(view);
|
public void | setUI(javax.swing.plaf.ScrollPaneUI ui)Sets the ScrollPaneUI object that provides the
look and feel (L&F) for this component.
super.setUI(ui);
|
public void | setVerticalScrollBar(javax.swing.JScrollBar verticalScrollBar)Adds the scrollbar that controls the viewports vertical view position
to the scrollpane. This is usually unnecessary,
as JScrollPane creates vertical and
horizontal scrollbars by default.
JScrollBar old = getVerticalScrollBar();
this.verticalScrollBar = verticalScrollBar;
add(verticalScrollBar, VERTICAL_SCROLLBAR);
firePropertyChange("verticalScrollBar", old, verticalScrollBar);
revalidate();
repaint();
|
public void | setVerticalScrollBarPolicy(int policy)Determines when the vertical scrollbar appears in the scrollpane.
Legal values are:
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
switch (policy) {
case VERTICAL_SCROLLBAR_AS_NEEDED:
case VERTICAL_SCROLLBAR_NEVER:
case VERTICAL_SCROLLBAR_ALWAYS:
break;
default:
throw new IllegalArgumentException("invalid verticalScrollBarPolicy");
}
int old = verticalScrollBarPolicy;
verticalScrollBarPolicy = policy;
firePropertyChange("verticalScrollBarPolicy", old, policy);
revalidate();
repaint();
|
public void | setViewport(javax.swing.JViewport viewport)Removes the old viewport (if there is one); forces the
viewPosition of the new viewport to be in the +x,+y quadrant;
syncs up the row and column headers (if there are any) with the
new viewport; and finally syncs the scrollbars and
headers with the new viewport.
Most applications will find it more convenient to use
setViewportView
to add a viewport and a view to the scrollpane.
JViewport old = getViewport();
this.viewport = viewport;
if (viewport != null) {
add(viewport, VIEWPORT);
}
else if (old != null) {
remove(old);
}
firePropertyChange("viewport", old, viewport);
if (accessibleContext != null) {
((AccessibleJScrollPane)accessibleContext).resetViewPort();
}
revalidate();
repaint();
|
public void | setViewportBorder(javax.swing.border.Border viewportBorder)Adds a border around the viewport. Note that the border isn't
set on the viewport directly, JViewport doesn't support
the JComponent border property.
Similarly setting the JScrollPane s
viewport doesn't affect the viewportBorder property.
The default value of this property is computed by the look
and feel implementation.
Border oldValue = this.viewportBorder;
this.viewportBorder = viewportBorder;
firePropertyChange("viewportBorder", oldValue, viewportBorder);
|
public void | setViewportView(java.awt.Component view)Creates a viewport if necessary and then sets its view. Applications
that don't provide the view directly to the JScrollPane
constructor
should use this method to specify the scrollable child that's going
to be displayed in the scrollpane. For example:
JScrollPane scrollpane = new JScrollPane();
scrollpane.setViewportView(myBigComponentToScroll);
Applications should not add children directly to the scrollpane.
if (getViewport() == null) {
setViewport(createViewport());
}
getViewport().setView(view);
|
public void | setWheelScrollingEnabled(boolean handleWheel)Enables/disables scrolling in response to movement of the mouse wheel.
Wheel scrolling is enabled by default.
boolean old = wheelScrollState;
wheelScrollState = handleWheel;
firePropertyChange("wheelScrollingEnabled", old, handleWheel);
|
public void | updateUI()Replaces the current ScrollPaneUI object with a version
from the current default look and feel.
To be called when the default look and feel changes.
setUI((ScrollPaneUI)UIManager.getUI(this));
|
private void | writeObject(java.io.ObjectOutputStream s)See readObject and writeObject in
JComponent for more
information about serialization in Swing.
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|