By default, JViewport is opaque. To change this, use the
setOpaque method.
NOTE:We have implemented a faster scrolling algorithm that does not require a buffer to draw in. The algorithm works as follows:
JComponents,
if they aren't, stop and repaint the whole viewport.
Window's graphics and
do a copyArea on the scrolled region.
copyAreas.
Compared to the non backing store case this
approach will greatly reduce the painted region.
This approach can cause slower times than the backing store approach when the viewport is obscured by another window, or partially offscreen. When another window obscures the viewport the copyArea will copy garbage and a paint event will be generated by the system to inform us we need to paint the newly exposed region. The only way to handle this is to repaint the whole viewport, which can cause slower performance than the backing store case. In most applications very rarely will the user be scrolling while the viewport is obscured by another window or offscreen, so this optimization is usually worth the performance hit when obscured.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
JScrollPane
| Modifier and Type | Class and Description |
|---|---|
| protected class | JViewport.
This class implements accessibility support for the
|
| pack-priv static class | |
| protected class | JViewport.
A listener for the view. |
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | backingStore
Deprecated
As of Java 2 platform v1.3
True when this viewport is maintaining an offscreen image of its
contents, so that some scrolling can take place using fast "bit-blit"
operations instead of by accessing the view object to construct the
display.
|
| public static final int | BACKINGSTORE_SCROLL_MODE
Draws viewport contents into an offscreen image. |
| protected transient Image | backingStoreImage
The view image used for a backing store. |
| public static final int | BLIT_SCROLL_MODE
Use |
| private transient ChangeEvent | |
| pack-priv static final Object | EnableWindowBlit
Property used to indicate window blitting should not be done. |
| private boolean | hasHadValidView
Whether or not a valid view has been installed. |
| private transient boolean | inBlitPaint
Set to true in paintView when paint is invoked. |
| protected boolean | isViewSizeSet
True when the viewport dimensions have been determined. |
| protected Point | lastPaintPosition
The last |
| private transient boolean | repaintAll
This is set to true in |
| private transient Timer | repaintTimer
Instead of directly invoking repaint, a |
| private int | |
| protected boolean | scrollUnderway
The |
| public static final int | SIMPLE_SCROLL_MODE
This mode uses the very simple method of redrawing the entire contents of the scrollpane each time it is scrolled. |
| private static final String | |
| private boolean | viewChanged
When view is changed we have to synchronize scrollbar values with viewport (see the BasicScrollPaneUI#syncScrollPaneWithViewport method). |
| private ComponentListener | |
| private transient boolean | waitingForRepaint
This is set to true in paint, if |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addChangeListener(ChangeListener
the l)ChangeListener to addAdds a |
| protected void | addImpl(Component
the lightweight child, Object child of the viewportthe constraints, int constraints to be respectedthe index index)Overrides java. Sets the |
| private void | blitDoubleBuffered(JComponent view, Graphics g, int clipX, int clipY, int clipW, int clipH, int blitFromX, int blitFromY, int blitToX, int blitToY, int blitW, int blitH)
|
| private boolean | canUseWindowBlitter()
Returns true if the viewport is not obscured by one of its ancestors, or its ancestors children and if the viewport is showing. |
| protected boolean | Returns: true if the parameters are modified and we're ready to blit; false otherwisethe horizontal delta dx, int the vertical delta dy, Point the blitFrom, Point Point we're blitting fromthe blitTo, Dimension Point we're blitting tothe blitSize, Rectangle Dimension of the area to blitthe area to blit blitPaint)Computes the parameters for a blit where the backing store image
currently contains |
| protected LayoutManager | Returns: aLayoutManagerSubclassers can override this to install a different
layout manager (or |
| private Timer | |
| private Image | |
| protected JViewport. | |
| protected void | firePropertyChange(String
a string containing the property name propertyName, Object the old value of the property oldValue, Object the new value of the property newValue)Overrides java. Notifies listeners of a property change. |
| protected void | fireStateChanged()
Notifies all |
| private void | flushViewDirtyRegion(Graphics
the g, Rectangle dirty)Graphics context within which to paintIf the repaint manager has a dirty region for the view, the view is asked to paint. |
| public AccessibleContext | Returns: an AccessibleJViewport that serves as the AccessibleContext of this JViewportOverrides java. Implements javax. Gets the AccessibleContext associated with this JViewport. |
| private Graphics | |
| public ChangeListener[] | Returns: all of theChangeListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public Dimension | Returns: aDimension object giving the size of the viewReturns the size of the visible part of the view in view coordinates. |
| public final Insets | Returns: aRectangle of zero dimension and zero originOverrides javax. Returns the insets (border) dimensions as (0,0,0,0), since borders
are not supported on a |
| public final Insets | Returns: this viewports inset valuesthe insets)Insets object which can be reusedOverrides javax. Returns an |
| public int | |
| public ViewportUI | Returns: aViewportUI objectOverrides javax. Returns the L&F object that renders this component. |
| public String | Returns: the string "ViewportUI"Overrides javax. Returns a string that specifies the name of the L&F class that renders this component. |
| public Component | Returns: the viewports child, ornull if none existsReturns the |
| private Point | |
| public Point | Returns: aPoint object giving the upper left coordinatesReturns the view coordinates that appear in the upper left hand corner of the viewport, or 0,0 if there's no view. |
| public Rectangle | Returns: aRectangle giving the visible part of
the view using view coordinates.Returns a rectangle whose origin is |
| public Dimension | Returns: aDimension object specifying the size of the viewIf the view's size hasn't been explicitly set, return the preferred size, otherwise return the view's current size. |
| public boolean | Returns: true if scrollMode is
BACKINGSTORE_SCROLL_MODE
Deprecated
As of Java 2 platform v1.3, replaced by
getScrollMode().
Returns |
| private boolean | |
| private boolean | |
| public boolean | Returns: falseOverrides javax. The |
| protected boolean | Returns: true if scroll mode is aBACKINGSTORE_SCROLL_MODE.Overrides javax. Returns true if scroll mode is a |
| private boolean | needsRepaintAfterBlit()
Returns true if the component needs to be completely repainted after a blit and a paint is received. |
| public void | paint(Graphics
the g)Graphics context within which to paintOverrides javax. Depending on whether the |
| private void | |
| private void | |
| private void | |
| protected String | Returns: a string representation of thisJViewportOverrides javax. Returns a string representation of this |
| private int | |
| public void | remove(Component child)
Overrides java. Removes the |
| public void | removeChangeListener(ChangeListener
the l)ChangeListener to removeRemoves a |
| public void | repaint(long
maximum time in milliseconds before update tm, int the x, int x coordinate (pixels over from left)the y, int y coordinate (pixels down from top)the width w, int the height h)Overrides javax. Always repaint in the parents coordinate system to make sure
only one paint is performed by the |
| public void | reshape(int
left edge of the origin x, int top edge of the origin y, int width in pixels w, int height in pixels h)Overrides javax. Sets the bounds of this viewport. |
| public void | scrollRectToVisible(Rectangle
the contentRect)Rectangle to displayOverrides javax. Scrolls the view so that |
| public void | setBackingStoreEnabled(boolean
if true, maintain an offscreen backing store enabled)
Deprecated
As of Java 2 platform v1.3, replaced by
setScrollMode().
If true if this viewport will maintain an offscreen image of its contents. |
| public final void | setBorder(Border
the border)Border to setOverrides javax. The viewport "scrolls" its child (called the "view") by the normal parent/child clipping (typically the view is moved in the opposite direction of the scroll). |
| public void | setExtentSize(Dimension
a newExtent)Dimension object specifying
the size of the viewSets the size of the visible part of the view using view coordinates. |
| public void | setScrollMode(int
one of the following values:
mode)
Used to control the method of scrolling the viewport contents. |
| public void | |
| public void | |
| public void | setViewPosition(Point
a p)Point object giving the upper left coordinatesSets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view. |
| public void | setViewSize(Dimension
a newSize)Dimension object specifying the new
size of the viewSets the size of the view. |
| public Dimension | Returns: aDimension object converted to view coordinatesa size)Dimension object using pixel coordinatesConverts a size in pixel coordinates to view coordinates. |
| public Point | Returns: aPoint object converted to view coordinatesa p)Point object using pixel coordinatesConverts a point in pixel coordinates to view coordinates. |
| public void | updateUI()
Overrides javax. Resets the UI property to a value from the current look and feel. |
| private void | validateView()
Ascends the |
| private boolean | Returns: true if blitting succeeded; otherwise falsethe g)Graphics context within which to paintUsed when blitting. |