Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.swing
Class JViewport

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Container
                  |
                  +--javax.swing.JComponent
                        |
                        +--javax.swing.JViewport

public class JViewport
extends JComponent
implements Accessible

The "viewport" or "porthole" through which you see the underlying information. When you scroll, what moves is the viewport. Its like peering through a camera's viewfinder. Moving the viewfinder upwards brings new things into view at the top of the picture and loses things that were at the bottom.

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. A future release of Swing will provide support for long term persistence.

See Also:
  `JScrollPane`, Serialized Form

Inner Class Summary
`protected class` | `JViewport.AccessibleJViewport` The class used to obtain the accessible role for this object.
`protected class` | `JViewport.ViewListener` A listener for the view.

Inner classes inherited from class javax.swing.JComponent
`JComponent.AccessibleJComponent`

Field Summary
`protected boolean` | `backingStore` 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.
`protected java.awt.Image` | `backingStoreImage` The view image used for a backing store.
`protected boolean` | `isViewSizeSet` True when the viewport dimensions have been determined.
`protected java.awt.Point` | `lastPaintPosition` The last viewPosition that we've painted, so we know how much of the backing store image is valid.
`protected boolean` | `scrollUnderway` The scrollUnderway flag is used for components like JList.

Fields inherited from class javax.swing.JComponent
`accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW`

Fields inherited from class java.awt.Component
`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

Constructor Summary
`JViewport()` Create a JViewPort

Method Summary
`void` | `addChangeListener(ChangeListener l)` Add a ChangeListener to the list that's notified each time the view's size, position, or the viewport's extent size has changed.
`protected void` | `addImpl(java.awt.Component child, java.lang.Object constraints, int index)` Sets the Viewport's one lightweight child, which can be null.
`protected boolean` | `computeBlit(int dx, int dy, java.awt.Point blitFrom, java.awt.Point blitTo, java.awt.Dimension blitSize, java.awt.Rectangle blitPaint)` Computes the parameters for a blit where the backing store image currently contains oldLoc in the upper left hand corner and we're scrolling to newLoc.
`protected java.awt.LayoutManager` | `createLayoutManager()` Subclassers can override this to install a different layout manager (or null) in the constructor.
`protected JViewport.ViewListener` | `createViewListener()` Create a listener for the view.
`protected void` | `fireStateChanged()`
`AccessibleContext` | `getAccessibleContext()` Get the AccessibleContext associated with this JComponent
`java.awt.Dimension` | `getExtentSize()` Returns the size of the visible part of the view in view coordinates.
`java.awt.Insets` | `getInsets()` Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on a JViewPort.
`java.awt.Insets` | `getInsets(java.awt.Insets insets)` Returns an Insets object containing this JViewPort's inset values.
`java.awt.Component` | `getView()` Returns the Viewport's one child or null.
`java.awt.Point` | `getViewPosition()` Returns the view coordinates that appear in the upper left hand corner of the viewport, 0,0 if there's no view.
`java.awt.Rectangle` | `getViewRect()` Return a rectangle whose origin is getViewPosition and size is getExtentSize().
`java.awt.Dimension` | `getViewSize()` If the view's size hasn't been explicitly set, return the preferred size, otherwise return the view's current size.
`boolean` | `isBackingStoreEnabled()` Returns true if this viewport is maintaining an offscreen image of its contents.
`boolean` | `isOptimizedDrawingEnabled()` The JViewport overrides the default implementation of this method (in JComponent) to return false.
`void` | `paint(java.awt.Graphics g)` Depending on whether the backingStore is enabled, either paint the image through the backing store or paint just the recently exposed part, using the backing store to "blit" the remainder.
`protected java.lang.String` | `paramString()` Returns a string representation of this JViewport.
`void` | `remove(java.awt.Component child)` Removes the Viewport's one lightweight child.
`void` | `removeChangeListener(ChangeListener l)` Remove a ChangeListener from the list that's notified each time the views size, position, or the viewports extent size has changed.
`void` | `repaint(long tm, int x, int y, int w, int h)` We always repaint in our parent coordinate system to make sure only one paint is performed by the RepaintManager.
`void` | `reshape(int x, int y, int w, int h)` Sets the bounds of this viewport.
`void` | `scrollRectToVisible(java.awt.Rectangle contentRect)` Overridden to scroll the view so that Rectangle within the view becomes visible.
`void` | `setBackingStoreEnabled(boolean x)` If true if this viewport will maintain an offscreen image of its contents.
`void` | `setBorder(Border border)` The viewport "scrolls" it's child (called the "view") by the normal parent/child clipping (typically the view is moved in the opposite direction of the scroll).
`void` | `setExtentSize(java.awt.Dimension newExtent)` Set the size of the visible part of the view using view coordinates.
`void` | `setView(java.awt.Component view)` Sets the Viewport's one lightweight child (`view`), which can be null.
`void` | `setViewPosition(java.awt.Point p)` Sets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view.
`void` | `setViewSize(java.awt.Dimension newSize)` Sets the view coordinates that appear in the upper left hand corner of the viewport, and the size of the view.
`java.awt.Dimension` | `toViewCoordinates(java.awt.Dimension size)` Convert a size in pixel coordinates to view coordinates.
`java.awt.Point` | `toViewCoordinates(java.awt.Point p)` Convert a point in pixel coordinates to view coordinates.

Methods inherited from class javax.swing.JComponent
`addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, revalidate, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI`

Methods inherited from class java.awt.Container
`add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setLayout, validate, validateTree`

Methods inherited from class java.awt.Component
`action, add, addComponentListener, addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, getBackground, getBounds, getColorModel, getCursor, getFont, getFontMetrics, getForeground, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isEnabled, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### isViewSizeSet

    protected boolean isViewSizeSet

  True when the viewport dimensions have been determined.

### lastPaintPosition

    protected java.awt.Point lastPaintPosition

  The last viewPosition that we've painted, so we know how much of the backing store image is valid.

### backingStore

    protected boolean backingStore

  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.

### backingStoreImage

    protected transient java.awt.Image backingStoreImage

  The view image used for a backing store.

### scrollUnderway

    protected boolean scrollUnderway

  The scrollUnderway flag is used for components like JList. When the downarrow key is pressed on a JList and the selected cell is the last in the list, the scrollpane autoscrolls. Here, the old selected cell needs repainting and so we need a flag to make the viewport do the optimised painting only when there is an explicit call to setViewPosition(Point). When setBounds() is called through other routes, the flag is off and the view repaints normally. Another approach would be to remove this from the Viewport class and have the JList manage this case by using setBackingStoreEnabled().

Constructor Detail

### JViewport

    public JViewport()

  Create a JViewPort

Method Detail

### addImpl

    protected void addImpl(java.awt.Component child,
                           java.lang.Object constraints,
                           int index)

  Sets the Viewport's one lightweight child, which can be null. (Since there is only one child which occupies the entire viewport, the constraints and index arguments are ignored.)
  Parameters:
    `child` - the Component ______________
    `constraints` - the Object ______________
    `index` - the int ______________
  Overrides:
    addImpl in class java.awt.Container
  See Also:
    `setView(java.awt.Component)`

### remove

    public void remove(java.awt.Component child)

  Removes the Viewport's one lightweight child.
  Overrides:
    remove in class java.awt.Container
  See Also:
    `setView(java.awt.Component)`

### scrollRectToVisible

    public void scrollRectToVisible(java.awt.Rectangle contentRect)

  Overridden to scroll the view so that Rectangle within the view becomes visible.
  Parameters:
    `contentRect` - the Rectangle to display
  Overrides:
    scrollRectToVisible in class JComponent

### setBorder

    public final void setBorder(Border border)

  The viewport "scrolls" it's child (called the "view") by the normal parent/child clipping (typically the view is moved in the opposite direction of the scroll). A non-null border, or non-zero insets, isn't supported, to prevent the geometry of this component from becoming complex enough to inhibit subclassing. To create a JViewport with a border, add it to a JPanel that has a border.
  Parameters:
    `border` - the Border to set
  Overrides:
    setBorder in class JComponent

### getInsets

    public final java.awt.Insets getInsets()

  Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on a JViewPort.
  Returns:
    new Insets(0, 0, 0, 0)
  Overrides:
    getInsets in class JComponent
  See Also:
    `setBorder(javax.swing.border.Border)`

### getInsets

    public final java.awt.Insets getInsets(java.awt.Insets insets)

  Returns an Insets object containing this JViewPort's inset values. The passed-in Insets object will be reinitialized, and all existing values within this object are overwritten.
  Parameters:
    `insets` - the Insets object which can be reused.
  Overrides:
    getInsets in class JComponent
  See Also:
    `getInsets()`

### isOptimizedDrawingEnabled

    public boolean isOptimizedDrawingEnabled()

  The JViewport overrides the default implementation of this method (in JComponent) to return false. This ensures that the drawing machinery will call the Viewport's paint() implementation rather than messaging the JViewport's children directly.
  Returns:
    false
  Overrides:
    isOptimizedDrawingEnabled in class JComponent

### paint

    public void paint(java.awt.Graphics g)

  Depending on whether the backingStore is enabled, either paint the image through the backing store or paint just the recently exposed part, using the backing store to "blit" the remainder.

  > The term "blit" is the pronounced version of the PDP-10 BLT (BLock Transfer) instruction, which copied a block of bits. (In case you were curious.)

  Parameters:
    `g` - the Graphics context within which to paint
  Overrides:
    paint in class JComponent

### reshape

    public void reshape(int x,
                        int y,
                        int w,
                        int h)

  Sets the bounds of this viewport. If the viewports width or height has changed, fire a StateChanged event.
  Parameters:
    `x` - left edge of the origin
    `y` - top edge of the origin
    `w` - width in pixels
    `h` - height in pixels
  Overrides:
    reshape in class JComponent
  See Also:
    `JComponent.reshape(int, int, int, int)`

### isBackingStoreEnabled

    public boolean isBackingStoreEnabled()

  Returns true if this viewport is maintaining an offscreen image of its contents.

### setBackingStoreEnabled

    public void setBackingStoreEnabled(boolean x)

  If true if this viewport will maintain an offscreen image of its contents. The image is used to reduce the cost of small one dimensional changes to the viewPosition. Rather than repainting the entire viewport we use Graphics.copyArea() to effect some of the scroll.

### getView

    public java.awt.Component getView()

  Returns the Viewport's one child or null.
  See Also:
    `setView(java.awt.Component)`

### setView

    public void setView(java.awt.Component view)

  Sets the Viewport's one lightweight child (`view`), which can be null.
  See Also:
    `getView()`

### getViewSize

    public java.awt.Dimension getViewSize()

  If the view's size hasn't been explicitly set, return the preferred size, otherwise return the view's current size. If there is no view, return 0,0.
  Returns:
    a Dimension object specifying the size of the view

### setViewSize

    public void setViewSize(java.awt.Dimension newSize)

  Sets the view coordinates that appear in the upper left hand corner of the viewport, and the size of the view.
  Parameters:
    `newSize` - a Dimension object specifying the size and location of the new view coordinates, or null if there is no view

### getViewPosition

    public java.awt.Point getViewPosition()

  Returns the view coordinates that appear in the upper left hand corner of the viewport, 0,0 if there's no view.
  Returns:
    a Point object giving the upper left coordinates

### setViewPosition

    public void setViewPosition(java.awt.Point p)

  Sets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view.
  Parameters:
    `p` - a Point object giving the upper left coordinates

### getViewRect

    public java.awt.Rectangle getViewRect()

  Return a rectangle whose origin is getViewPosition and size is getExtentSize(). This is the visible part of the view, in view coordinates.
  Returns:
    a Rectangle giving the visible part of the view using view coordinates.

### computeBlit

    protected boolean computeBlit(int dx,
                                  int dy,
                                  java.awt.Point blitFrom,
                                  java.awt.Point blitTo,
                                  java.awt.Dimension blitSize,
                                  java.awt.Rectangle blitPaint)

  Computes the parameters for a blit where the backing store image currently contains oldLoc in the upper left hand corner and we're scrolling to newLoc. The parameters are modified to return the values required for the blit.

### getExtentSize

    public java.awt.Dimension getExtentSize()

  Returns the size of the visible part of the view in view coordinates.
  Returns:
    a Dimension object giving the size of the view

### toViewCoordinates

    public java.awt.Dimension toViewCoordinates(java.awt.Dimension size)

  Convert a size in pixel coordinates to view coordinates. Subclasses of viewport that support "logical coordinates" will override this method.
  Parameters:
    `size` - a Dimension object using pixel coordinates
  Returns:
    a Dimension object converted to view coordinates

### toViewCoordinates

    public java.awt.Point toViewCoordinates(java.awt.Point p)

  Convert a point in pixel coordinates to view coordinates. Subclasses of viewport that support "logical coordinates" will override this method.
  Parameters:
    `p` - a Point object using pixel coordinates
  Returns:
    a Point object converted to view coordinates

### setExtentSize

    public void setExtentSize(java.awt.Dimension newExtent)

  Set the size of the visible part of the view using view coordinates.
  Parameters:
    `newExtent` - a Dimension object specifying the size of the view

### createViewListener

    protected JViewport.ViewListener createViewListener()

  Create a listener for the view.
  Returns:
    a ViewListener

### createLayoutManager

    protected java.awt.LayoutManager createLayoutManager()

  Subclassers can override this to install a different layout manager (or null) in the constructor. Returns a new JViewportLayout object.
  Returns:
    a LayoutManager

### addChangeListener

    public void addChangeListener(ChangeListener l)

  Add a ChangeListener to the list that's notified each time the view's size, position, or the viewport's extent size has changed.
  Parameters:
    `l` - the ChangeListener to add
  See Also:
    `removeChangeListener(javax.swing.event.ChangeListener)`, `setViewPosition(java.awt.Point)`, `setViewSize(java.awt.Dimension)`, `setExtentSize(java.awt.Dimension)`

### removeChangeListener

    public void removeChangeListener(ChangeListener l)

  Remove a ChangeListener from the list that's notified each time the views size, position, or the viewports extent size has changed.
  Parameters:
    `l` - the ChangeListener to remove
  See Also:
    `addChangeListener(javax.swing.event.ChangeListener)`

### fireStateChanged

    protected void fireStateChanged()

### repaint

    public void repaint(long tm,
                        int x,
                        int y,
                        int w,
                        int h)

  We always repaint in our parent coordinate system to make sure only one paint is performed by the RepaintManager.
  Parameters:
    `tm` - maximum time in milliseconds before update
    `x` - the x coordinate (pixels over from left)
    `y` - the y coordinate (pixels down from top)
    `width` - the width
    `height` - the height
  Overrides:
    repaint in class JComponent
  See Also:
    `Component.update(java.awt.Graphics)`

### paramString

    protected java.lang.String paramString()

  Returns a string representation of this JViewport. 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`.

  Overriding paramString() to provide information about the specific new aspects of the JFC components.

  Returns:
    a string representation of this JViewport.
  Overrides:
    paramString in class JComponent

### getAccessibleContext

    public AccessibleContext getAccessibleContext()

  Get the AccessibleContext associated with this JComponent
  Specified by:
    getAccessibleContext in interface Accessible
  Returns:
    the AccessibleContext of this JComponent
  Overrides:
    getAccessibleContext in class JComponent

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.