- java.lang.Object
- 
- java.awt.Component
- 
- java.awt.Container
- 
- javax.swing.JComponent
- 
- javax.swing.JViewport
 
 
 
 
- 
- All Implemented Interfaces:
- ImageObserver,- MenuContainer,- Serializable,- Accessible
 
 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. It is 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.By default, JViewportis opaque. To change this, use thesetOpaquemethod.NOTE:We have implemented a faster scrolling algorithm that does not require a buffer to draw in. The algorithm works as follows: - The view and parent view and checked to see if they are
 JComponents, if they aren't, stop and repaint the whole viewport.
- If the viewport is obscured by an ancestor, stop and repaint the whole viewport.
- Compute the region that will become visible, if it is as big as the viewport, stop and repaint the whole view region.
- Obtain the ancestor Window's graphics and do acopyAreaon the scrolled region.
- Message the view to repaint the newly visible region.
- The next time paint is invoked on the viewport, if the clip region is smaller than the viewport size a timer is kicked off to repaint the whole 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.beanspackage. Please seeXMLEncoder.- Since:
- 1.2
- See Also:
- JScrollPane, Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classJViewport.AccessibleJViewportThis class implements accessibility support for theJViewportclass.protected classJViewport.ViewListenerA listener for the view.- 
Nested classes/interfaces declared in class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 - 
Nested classes/interfaces declared in class java.awt.ContainerContainer.AccessibleAWTContainer
 - 
Nested classes/interfaces declared in class javax.swing.JComponentJComponent.AccessibleJComponent
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected booleanbackingStoreDeprecated.As of Java 2 platform v1.3static intBACKINGSTORE_SCROLL_MODEDraws viewport contents into an offscreen image.protected ImagebackingStoreImageThe view image used for a backing store.static intBLIT_SCROLL_MODEUsegraphics.copyAreato implement scrolling.protected booleanisViewSizeSetTrue when the viewport dimensions have been determined.protected PointlastPaintPositionThe lastviewPositionthat we've painted, so we know how much of the backing store image is valid.protected booleanscrollUnderwayThescrollUnderwayflag is used for components likeJList.static intSIMPLE_SCROLL_MODEThis mode uses the very simple method of redrawing the entire contents of the scrollpane each time it is scrolled.- 
Fields declared in class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 - 
Fields declared in interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 - 
Fields declared in class javax.swing.JComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
- 
 - 
Constructor SummaryConstructors Constructor Description JViewport()Creates aJViewport.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChangeListener(ChangeListener l)Adds aChangeListenerto the list that is notified each time the view's size, position, or the viewport's extent size has changed.protected voidaddImpl(Component child, Object constraints, int index)Sets theJViewport's one lightweight child, which can benull.protected booleancomputeBlit(int dx, int dy, Point blitFrom, Point blitTo, Dimension blitSize, Rectangle blitPaint)Computes the parameters for a blit where the backing store image currently containsoldLocin the upper left hand corner and we're scrolling tonewLoc.protected LayoutManagercreateLayoutManager()Subclassers can override this to install a different layout manager (ornull) in the constructor.protected JViewport.ViewListenercreateViewListener()Creates a listener for the view.protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue)Notifies listeners of a property change.protected voidfireStateChanged()Notifies allChangeListenerswhen the views size, position, or the viewports extent size has changed.AccessibleContextgetAccessibleContext()Gets the AccessibleContext associated with this JViewport.ChangeListener[]getChangeListeners()Returns an array of all theChangeListeners added to this JViewport with addChangeListener().DimensiongetExtentSize()Returns the size of the visible part of the view in view coordinates.InsetsgetInsets()Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on aJViewport.InsetsgetInsets(Insets insets)Returns anInsetsobject containing thisJViewports inset values.intgetScrollMode()Returns the current scrolling mode.ViewportUIgetUI()Returns the L&F object that renders this component.StringgetUIClassID()Returns a string that specifies the name of the L&F class that renders this component.ComponentgetView()Returns theJViewport's one child ornull.PointgetViewPosition()Returns the view coordinates that appear in the upper left hand corner of the viewport, or 0,0 if there's no view.RectanglegetViewRect()Returns a rectangle whose origin isgetViewPositionand size isgetExtentSize.DimensiongetViewSize()If the view's size hasn't been explicitly set, return the preferred size, otherwise return the view's current size.booleanisBackingStoreEnabled()Deprecated.As of Java 2 platform v1.3, replaced bygetScrollMode().booleanisOptimizedDrawingEnabled()TheJViewportoverrides the default implementation of this method (inJComponent) to return false.protected booleanisPaintingOrigin()Returns true if scroll mode is aBACKINGSTORE_SCROLL_MODEto cause painting to originate fromJViewport, or one of its ancestors.voidpaint(Graphics g)Depending on whether thebackingStoreis 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 StringparamString()Returns a string representation of thisJViewport.voidremove(Component child)Removes theViewports one lightweight child.voidremoveChangeListener(ChangeListener l)Removes aChangeListenerfrom the list that's notified each time the views size, position, or the viewports extent size has changed.voidrepaint(long tm, int x, int y, int w, int h)Always repaint in the parents coordinate system to make sure only one paint is performed by theRepaintManager.voidreshape(int x, int y, int w, int h)Sets the bounds of this viewport.voidscrollRectToVisible(Rectangle contentRect)Scrolls the view so thatRectanglewithin the view becomes visible.voidsetBackingStoreEnabled(boolean enabled)Deprecated.As of Java 2 platform v1.3, replaced bysetScrollMode().voidsetBorder(Border border)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).voidsetExtentSize(Dimension newExtent)Sets the size of the visible part of the view using view coordinates.voidsetScrollMode(int mode)Used to control the method of scrolling the viewport contents.voidsetUI(ViewportUI ui)Sets the L&F object that renders this component.voidsetView(Component view)Sets theJViewport's one lightweight child (view), which can benull.voidsetViewPosition(Point p)Sets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view.voidsetViewSize(Dimension newSize)Sets the size of the view.DimensiontoViewCoordinates(Dimension size)Converts a size in pixel coordinates to view coordinates.PointtoViewCoordinates(Point p)Converts a point in pixel coordinates to view coordinates.voidupdateUI()Resets the UI property to a value from the current look and feel.- 
Methods declared in class java.awt.Componentaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 - 
Methods declared in class java.awt.Containeradd, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 - 
Methods declared in class javax.swing.JComponentaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
- 
 
- 
- 
- 
Field Detail- 
isViewSizeSetprotected boolean isViewSizeSet True when the viewport dimensions have been determined. The default is false.
 - 
lastPaintPositionprotected Point lastPaintPosition The lastviewPositionthat we've painted, so we know how much of the backing store image is valid.
 - 
backingStore@Deprecated protected boolean backingStore Deprecated.As of Java 2 platform v1.3True 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. The default isfalse.- See Also:
- setScrollMode(int)
 
 - 
backingStoreImageprotected transient Image backingStoreImage The view image used for a backing store.
 - 
scrollUnderwayprotected boolean scrollUnderway ThescrollUnderwayflag is used for components likeJList. When the downarrow key is pressed on aJListand the selected cell is the last in the list, thescrollpaneautoscrolls. Here, the old selected cell needs repainting and so we need a flag to make the viewport do the optimized painting only when there is an explicit call tosetViewPosition(Point). WhensetBoundsis called through other routes, the flag is off and the view repaints normally. Another approach would be to remove this from theJViewportclass and have theJListmanage this case by usingsetBackingStoreEnabled. The default isfalse.
 - 
BLIT_SCROLL_MODEpublic static final int BLIT_SCROLL_MODE Usegraphics.copyAreato implement scrolling. This is the fastest for most applications.- Since:
- 1.3
- See Also:
- setScrollMode(int), Constant Field Values
 
 - 
BACKINGSTORE_SCROLL_MODEpublic static final int BACKINGSTORE_SCROLL_MODE Draws viewport contents into an offscreen image. This was previously the default mode forJTable. This mode may offer advantages over "blit mode" in some cases, but it requires a large chunk of extra RAM.- Since:
- 1.3
- See Also:
- setScrollMode(int), Constant Field Values
 
 - 
SIMPLE_SCROLL_MODEpublic 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. This was the default behavior in Swing 1.0 and Swing 1.1. Either of the other two options will provide better performance in most cases.- Since:
- 1.3
- See Also:
- setScrollMode(int), Constant Field Values
 
 
- 
 - 
Method Detail- 
getUIpublic ViewportUI getUI() Returns the L&F object that renders this component.- Overrides:
- getUIin class- JComponent
- Returns:
- a ViewportUIobject
- Since:
- 1.3
 
 - 
setUI@BeanProperty(hidden=true, visualUpdate=true, description="The UI object that implements the Component\'s LookAndFeel.") public void setUI(ViewportUI ui) Sets the L&F object that renders this component.- Parameters:
- ui- the- ViewportUIL&F object
- Since:
- 1.3
- See Also:
- UIDefaults.getUI(javax.swing.JComponent)
 
 - 
updateUIpublic void updateUI() Resets the UI property to a value from the current look and feel.- Overrides:
- updateUIin class- JComponent
- See Also:
- JComponent.updateUI()
 
 - 
getUIClassIDpublic String getUIClassID() Returns a string that specifies the name of the L&F class that renders this component.- Overrides:
- getUIClassIDin class- JComponent
- Returns:
- the string "ViewportUI"
- See Also:
- JComponent.getUIClassID(),- UIDefaults.getUI(javax.swing.JComponent)
 
 - 
addImplprotected void addImpl(Component child, Object constraints, int index) Sets theJViewport's one lightweight child, which can benull. (Since there is only one child which occupies the entire viewport, theconstraintsandindexarguments are ignored.)- Overrides:
- addImplin class- Container
- Parameters:
- child- the lightweight- childof the viewport
- constraints- the- constraintsto be respected
- index- the index
- See Also:
- setView(java.awt.Component)
 
 - 
removepublic void remove(Component child) Removes theViewports one lightweight child.- Overrides:
- removein class- Container
- Parameters:
- child- the component to be removed
- See Also:
- setView(java.awt.Component)
 
 - 
scrollRectToVisiblepublic void scrollRectToVisible(Rectangle contentRect) Scrolls the view so thatRectanglewithin the view becomes visible.This attempts to validate the view before scrolling if the view is currently not valid - isValidreturns false. To avoid excessive validation when the containment hierarchy is being created this will not validate if one of the ancestors does not have a peer, or there is no validate root ancestor, or one of the ancestors is not aWindoworApplet.Note that this method will not scroll outside of the valid viewport; for example, if contentRectis larger than the viewport, scrolling will be confined to the viewport's bounds.- Overrides:
- scrollRectToVisiblein class- JComponent
- Parameters:
- contentRect- the- Rectangleto display
- See Also:
- JComponent.isValidateRoot(),- Component.isValid()
 
 - 
setBorderpublic final void setBorder(Border border) 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). A non-nullborder, or non-zero insets, isn't supported, to prevent the geometry of this component from becoming complex enough to inhibit subclassing. To create aJViewportwith a border, add it to aJPanelthat has a border.Note: If borderis non-null, this method will throw an exception as borders are not supported on aJViewPort.- Overrides:
- setBorderin class- JComponent
- Parameters:
- border- the- Borderto set
- Throws:
- IllegalArgumentException- this method is not implemented
- See Also:
- Border,- CompoundBorder
 
 - 
getInsetspublic final Insets getInsets() Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on aJViewport.- Overrides:
- getInsetsin class- JComponent
- Returns:
- a Rectangleof zero dimension and zero origin
- See Also:
- setBorder(javax.swing.border.Border)
 
 - 
getInsets@BeanProperty(expert=true) public final Insets getInsets(Insets insets) Returns anInsetsobject containing thisJViewports inset values. The passed-inInsetsobject will be reinitialized, and all existing values within this object are overwritten.- Overrides:
- getInsetsin class- JComponent
- Parameters:
- insets- the- Insetsobject which can be reused
- Returns:
- this viewports inset values
- See Also:
- getInsets()
 
 - 
isOptimizedDrawingEnabledpublic boolean isOptimizedDrawingEnabled() TheJViewportoverrides the default implementation of this method (inJComponent) to return false. This ensures that the drawing machinery will call theViewport'spaintimplementation rather than messaging theJViewport's children directly.- Overrides:
- isOptimizedDrawingEnabledin class- JComponent
- Returns:
- false
 
 - 
isPaintingOriginprotected boolean isPaintingOrigin() Returns true if scroll mode is aBACKINGSTORE_SCROLL_MODEto cause painting to originate fromJViewport, or one of its ancestors. Otherwise returnsfalse.- Overrides:
- isPaintingOriginin class- JComponent
- Returns:
- true if scroll mode is a BACKINGSTORE_SCROLL_MODE.
- See Also:
- JComponent.isPaintingOrigin()
 
 - 
paintpublic void paint(Graphics g) Depending on whether thebackingStoreis 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.) - Overrides:
- paintin class- JComponent
- Parameters:
- g- the- Graphicscontext within which to paint
- See Also:
- JComponent.paintComponent(java.awt.Graphics),- JComponent.paintBorder(java.awt.Graphics),- JComponent.paintChildren(java.awt.Graphics),- JComponent.getComponentGraphics(java.awt.Graphics),- JComponent.repaint(long, int, int, int, int)
 
 - 
reshapepublic void reshape(int x, int y, int w, int h)Sets the bounds of this viewport. If the viewport's width or height has changed, fire aStateChangedevent.- Overrides:
- reshapein class- JComponent
- Parameters:
- x- left edge of the origin
- y- top edge of the origin
- w- width in pixels
- h- height in pixels
- See Also:
- JComponent.reshape(int, int, int, int)
 
 - 
setScrollMode@BeanProperty(bound=false, enumerationValues={"JViewport.BLIT_SCROLL_MODE","JViewport.BACKINGSTORE_SCROLL_MODE","JViewport.SIMPLE_SCROLL_MODE"}, description="Method of moving contents for incremental scrolls.") public void setScrollMode(int mode) Used to control the method of scrolling the viewport contents. You may want to change this mode to get maximum performance for your use case.- Parameters:
- mode- one of the following values:- JViewport.BLIT_SCROLL_MODE
- JViewport.BACKINGSTORE_SCROLL_MODE
- JViewport.SIMPLE_SCROLL_MODE
 
- Since:
- 1.3
- See Also:
- BLIT_SCROLL_MODE,- BACKINGSTORE_SCROLL_MODE,- SIMPLE_SCROLL_MODE
 
 - 
getScrollModepublic int getScrollMode() Returns the current scrolling mode.- Returns:
- the scrollModeproperty
- Since:
- 1.3
- See Also:
- setScrollMode(int)
 
 - 
isBackingStoreEnabled@Deprecated public boolean isBackingStoreEnabled() Deprecated.As of Java 2 platform v1.3, replaced bygetScrollMode().Returnstrueif this viewport is maintaining an offscreen image of its contents.- Returns:
- trueif- scrollModeis- BACKINGSTORE_SCROLL_MODE
 
 - 
setBackingStoreEnabled@Deprecated public void setBackingStoreEnabled(boolean enabled) Deprecated.As of Java 2 platform v1.3, replaced bysetScrollMode().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 theviewPosition. Rather than repainting the entire viewport we useGraphics.copyAreato effect some of the scroll.- Parameters:
- enabled- if true, maintain an offscreen backing store
 
 - 
getViewpublic Component getView() Returns theJViewport's one child ornull.- Returns:
- the viewports child, or nullif none exists
- See Also:
- setView(java.awt.Component)
 
 - 
setViewpublic void setView(Component view) Sets theJViewport's one lightweight child (view), which can benull.- Parameters:
- view- the viewport's new lightweight child
- See Also:
- getView()
 
 - 
getViewSizepublic 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 Dimensionobject specifying the size of the view
 
 - 
setViewSizepublic void setViewSize(Dimension newSize) Sets the size of the view. A state changed event will be fired.- Parameters:
- newSize- a- Dimensionobject specifying the new size of the view
 
 - 
getViewPositionpublic Point getViewPosition() Returns the view coordinates that appear in the upper left hand corner of the viewport, or 0,0 if there's no view.- Returns:
- a Pointobject giving the upper left coordinates
 
 - 
setViewPositionpublic void setViewPosition(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- Pointobject giving the upper left coordinates
 
 - 
getViewRectpublic Rectangle getViewRect() Returns a rectangle whose origin isgetViewPositionand size isgetExtentSize. This is the visible part of the view, in view coordinates.- Returns:
- a Rectanglegiving the visible part of the view using view coordinates.
 
 - 
computeBlitprotected boolean computeBlit(int dx, int dy, Point blitFrom, Point blitTo, Dimension blitSize, Rectangle blitPaint)Computes the parameters for a blit where the backing store image currently containsoldLocin the upper left hand corner and we're scrolling tonewLoc. The parameters are modified to return the values required for the blit.- Parameters:
- dx- the horizontal delta
- dy- the vertical delta
- blitFrom- the- Pointwe're blitting from
- blitTo- the- Pointwe're blitting to
- blitSize- the- Dimensionof the area to blit
- blitPaint- the area to blit
- Returns:
- true if the parameters are modified and we're ready to blit; false otherwise
 
 - 
getExtentSizepublic Dimension getExtentSize() Returns the size of the visible part of the view in view coordinates.- Returns:
- a Dimensionobject giving the size of the view
 
 - 
toViewCoordinatespublic Dimension toViewCoordinates(Dimension size) Converts a size in pixel coordinates to view coordinates. Subclasses of viewport that support "logical coordinates" will override this method.- Parameters:
- size- a- Dimensionobject using pixel coordinates
- Returns:
- a Dimensionobject converted to view coordinates
 
 - 
toViewCoordinatespublic Point toViewCoordinates(Point p) Converts a point in pixel coordinates to view coordinates. Subclasses of viewport that support "logical coordinates" will override this method.- Parameters:
- p- a- Pointobject using pixel coordinates
- Returns:
- a Pointobject converted to view coordinates
 
 - 
setExtentSizepublic void setExtentSize(Dimension newExtent) Sets the size of the visible part of the view using view coordinates.- Parameters:
- newExtent- a- Dimensionobject specifying the size of the view
 
 - 
createViewListenerprotected JViewport.ViewListener createViewListener() Creates a listener for the view.- Returns:
- a ViewListener
 
 - 
createLayoutManagerprotected LayoutManager createLayoutManager() Subclassers can override this to install a different layout manager (ornull) in the constructor. Returns theLayoutManagerto install on theJViewport.- Returns:
- a LayoutManager
 
 - 
addChangeListenerpublic void addChangeListener(ChangeListener l) Adds aChangeListenerto the list that is notified each time the view's size, position, or the viewport's extent size has changed.- Parameters:
- l- the- ChangeListenerto add
- See Also:
- removeChangeListener(javax.swing.event.ChangeListener),- setViewPosition(java.awt.Point),- setViewSize(java.awt.Dimension),- setExtentSize(java.awt.Dimension)
 
 - 
removeChangeListenerpublic void removeChangeListener(ChangeListener l) Removes aChangeListenerfrom the list that's notified each time the views size, position, or the viewports extent size has changed.- Parameters:
- l- the- ChangeListenerto remove
- See Also:
- addChangeListener(javax.swing.event.ChangeListener)
 
 - 
getChangeListenerspublic ChangeListener[] getChangeListeners() Returns an array of all theChangeListeners added to this JViewport with addChangeListener().- Returns:
- all of the ChangeListeners added or an empty array if no listeners have been added
- Since:
- 1.4
 
 - 
fireStateChangedprotected void fireStateChanged() Notifies allChangeListenerswhen the views size, position, or the viewports extent size has changed.
 - 
repaintpublic void repaint(long tm, int x, int y, int w, int h)Always repaint in the parents coordinate system to make sure only one paint is performed by theRepaintManager.- Overrides:
- repaintin class- JComponent
- Parameters:
- tm- maximum time in milliseconds before update
- x- the- xcoordinate (pixels over from left)
- y- the- ycoordinate (pixels down from top)
- w- the width
- h- the height
- See Also:
- Component.update(java.awt.Graphics)
 
 - 
paramStringprotected String paramString() Returns a string representation of thisJViewport. 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 benull.- Overrides:
- paramStringin class- JComponent
- Returns:
- a string representation of this JViewport
 
 - 
firePropertyChangeprotected void firePropertyChange(String propertyName, Object oldValue, Object newValue) Notifies listeners of a property change. This is subclassed to update thewindowBlitproperty. (TheputClientPropertyproperty is final).- Overrides:
- firePropertyChangein class- Component
- Parameters:
- propertyName- a string containing the property name
- oldValue- the old value of the property
- newValue- the new value of the property
 
 - 
getAccessibleContextpublic AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this JViewport. For viewports, the AccessibleContext takes the form of an AccessibleJViewport. A new AccessibleJViewport instance is created if necessary.- Specified by:
- getAccessibleContextin interface- Accessible
- Overrides:
- getAccessibleContextin class- Component
- Returns:
- an AccessibleJViewport that serves as the AccessibleContext of this JViewport
 
 
- 
 
-