javax.swing

Class JViewport

Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class JViewport
extends JComponent

                                                     _
   +-------------------------------+    ...........Y1 \
   |  view                         |                .  \
   |  (this component's child)     |                .   > VY
   |                               |                .  / = Y2-Y1
   |         +------------------------------+  ....Y2_/
   |         | viewport            |        |       .
   |         | (this component)    |        |       .
   |         |                     |        |       .
   |         |                     |        |       .
   |         |                     |        |       .
   |         |                     |        |       .
   |         +------------------------------+  ....Y3
   |                               |                .
   |         .                     |        .       .
   |         .                     |        .       .
   +---------.---------------------+    ...........Y4
   .         .                     .        .
   .         .                     .        .
   .         .                     .        .
   X1.......X2.....................X3.......X4
   \____  ___/
        \/
        VX = X2-X1

A viewport is, like all swing components, located at some position in the swing component tree; that location is exactly the same as any other components: the viewport's "bounds".

But in terms of drawing its child, the viewport thinks of itself as covering a particular position of the view's coordinate space. For example, the getViewPosition() method returns the position (VX,VY) shown above, which is an position in "view space", even though this is implemented by positioning the underlying child at position (-VX,-VY)

See Also:
Serialized Form

Nested Class Summary

protected class
JViewport.ViewListener
A ComponentListener that listens for changes of the view's size.

Nested classes/interfaces inherited from class javax.swing.JComponent

JComponent.AccessibleJComponent

Nested classes/interfaces inherited from class java.awt.Container

Container.AccessibleAWTContainer

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

static int
BACKINGSTORE_SCROLL_MODE
static int
BLIT_SCROLL_MODE
static int
SIMPLE_SCROLL_MODE
protected boolean
isViewSizeSet
protected boolean
scrollUnderway

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

JViewport()
Creates a new JComponent instance.

Method Summary

void
addChangeListener(ChangeListener listener)
protected void
addImpl(Component comp, Object constraints, int index)
This method is called by all the add() methods to perform the actual adding of the component.
protected LayoutManager
createLayoutManager()
Creates the LayoutManager that is used for this viewport.
protected JViewport.ViewListener
createViewListener()
Creates a JViewport.ViewListener that is supposed to listen for size changes on the view component.
protected void
fireStateChanged()
ChangeListener[]
getChangeListeners()
Dimension
getExtentSize()
Insets
getInsets()
Get the component's insets, which are calculated from the JComponent property.
Insets
getInsets(Insets insets)
Get the component's insets, which are calculated from the JComponent property.
int
getScrollMode()
ViewportUI
getUI()
This method returns the viewport's UI delegate.
String
getUIClassID()
This method returns the String ID of the UI class of Separator.
Component
getView()
Point
getViewPosition()
Get the viewport's position in view space.
Rectangle
getViewRect()
Dimension
getViewSize()
Returns the viewSize when set, or the preferred size of the set Component view.
boolean
isBackingStoreEnabled()
Deprecated. 1.4
boolean
isOptimizedDrawingEnabled()
Return true if the component can guarantee that none of its children will overlap in Z-order.
void
paint(Graphics g)
Paint the component.
void
removeChangeListener(ChangeListener listener)
void
reshape(int x, int y, int w, int h)
Moves and resizes the component.
void
revalidate()
Queue a an invalidation and revalidation of this component, using RepaintManager.addInvalidComponent(JComponent).
void
scrollRectToVisible(Rectangle contentRect)
Scrolls the view so that contentRect becomes visible.
void
setBackingStoreEnabled(boolean b)
Deprecated. 1.4
void
setBorder(Border border)
Set the value of the JComponent property.
void
setExtentSize(Dimension newSize)
void
setScrollMode(int mode)
void
setUI(ViewportUI ui)
This method sets the viewport's UI delegate.
void
setView(Component v)
void
setViewPosition(Point p)
void
setViewSize(Dimension newSize)
Dimension
toViewCoordinates(Dimension size)
Point
toViewCoordinates(Point p)
void
updateUI()
This method resets the UI used to the Look and Feel defaults..

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, swapComponents, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

BACKINGSTORE_SCROLL_MODE

public static final int BACKINGSTORE_SCROLL_MODE

Field Value:
2


BLIT_SCROLL_MODE

public static final int BLIT_SCROLL_MODE

Field Value:
1


SIMPLE_SCROLL_MODE

public static final int SIMPLE_SCROLL_MODE

Field Value:
0


isViewSizeSet

protected boolean isViewSizeSet


scrollUnderway

protected boolean scrollUnderway

Constructor Details

JViewport

public JViewport()
Creates a new JComponent instance.

Method Details

addChangeListener

public void addChangeListener(ChangeListener listener)


addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
This method is called by all the add() methods to perform the actual adding of the component. Subclasses who wish to perform their own processing when a component is added should override this method. Any subclass doing this must call the superclass version of this method in order to ensure proper functioning of the container.
Overrides:
addImpl in interface Container

Parameters:
comp - The component to be added.
constraints - The layout constraints for this component, or null if there are no constraints.
index - The index in the component list to insert this child at, or -1 to add at the end of the list.

Throws:
ArrayIndexOutOfBoundsException - If the specified index is invalid.


createLayoutManager

protected LayoutManager createLayoutManager()
Creates the LayoutManager that is used for this viewport. Override this method if you want to use a custom LayoutManager.

Returns:
a LayoutManager to use for this viewport


createViewListener

protected JViewport.ViewListener createViewListener()
Creates a JViewport.ViewListener that is supposed to listen for size changes on the view component.

Returns:
a ViewListener instance


fireStateChanged

protected void fireStateChanged()


getChangeListeners

public ChangeListener[] getChangeListeners()


getExtentSize

public Dimension getExtentSize()


getInsets

public final Insets getInsets()
Get the component's insets, which are calculated from the JComponent property. If the border is null, calls Container.getInsets().
Overrides:
getInsets in interface JComponent

Returns:
The component's current insets


getInsets

public final Insets getInsets(Insets insets)
Get the component's insets, which are calculated from the JComponent property. If the border is null, calls Container.getInsets(). The passed-in Insets value will be used as the return value, if possible.
Overrides:
getInsets in interface JComponent

Parameters:
insets - Return value object to reuse, if possible

Returns:
The component's current insets


getScrollMode

public int getScrollMode()


getUI

public ViewportUI getUI()
This method returns the viewport's UI delegate.

Returns:
The viewport's UI delegate.


getUIClassID

public String getUIClassID()
This method returns the String ID of the UI class of Separator.
Overrides:
getUIClassID in interface JComponent

Returns:
The UI class' String ID.


getView

public Component getView()


getViewPosition

public Point getViewPosition()
Get the viewport's position in view space. Despite confusing name, this really does return the viewport's (0,0) position in view space, not the view's position.


getViewRect

public Rectangle getViewRect()


getViewSize

public Dimension getViewSize()
Returns the viewSize when set, or the preferred size of the set Component view. If no viewSize and no Component view is set an empty Dimension is returned.


isBackingStoreEnabled

public boolean isBackingStoreEnabled()

Deprecated. 1.4


isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()
Return true if the component can guarantee that none of its children will overlap in Z-order. This is a hint to the painting system. The default is to return true, but some components such as JLayeredPane should override this to return false.
Overrides:
isOptimizedDrawingEnabled in interface JComponent

Returns:
Whether the component tiles its children


paint

public void paint(Graphics g)
Paint the component. This is a delicate process, and should only be called from the repaint thread, under control of the RepaintManager. Client code should usually call JComponent.repaint() to trigger painting.

This method will acquire a double buffer from the RepaintManager if the component's JComponent property is true and the paint call is the first recursive paint call inside swing.

The method will also modify the provided Graphics context via the JComponent.getComponentGraphics(Graphics) method. If you want to customize the graphics object used for painting, you should override that method rather than paint.

The body of the paint call involves calling JComponent.paintComponent(Graphics), JComponent.paintBorder(Graphics), and JComponent.paintChildren(Graphics) in order. If you want to customize painting behavior, you should override one of these methods rather than paint.

For more details on the painting sequence, see this article.

Overrides:
paint in interface JComponent

Parameters:
g - The graphics context to paint with

See Also:
JComponent.paintImmediately(Rectangle)


removeChangeListener

public void removeChangeListener(ChangeListener listener)


reshape

public void reshape(int x,
                    int y,
                    int w,
                    int h)
Moves and resizes the component.
Overrides:
reshape in interface JComponent

Parameters:
x - the new horizontal location
y - the new vertial location
w - the new width
h - the new height


revalidate

public void revalidate()
Queue a an invalidation and revalidation of this component, using RepaintManager.addInvalidComponent(JComponent).
Overrides:
revalidate in interface JComponent


scrollRectToVisible

public void scrollRectToVisible(Rectangle contentRect)
Scrolls the view so that contentRect becomes visible.
Overrides:
scrollRectToVisible in interface JComponent

Parameters:
contentRect - the rectangle to make visible within the view


setBackingStoreEnabled

public void setBackingStoreEnabled(boolean b)

Deprecated. 1.4


setBorder

public final void setBorder(Border border)
Set the value of the JComponent property.
Overrides:
setBorder in interface JComponent

Parameters:

See Also:
JComponent.getBorder()


setExtentSize

public void setExtentSize(Dimension newSize)


setScrollMode

public void setScrollMode(int mode)


setUI

public void setUI(ViewportUI ui)
This method sets the viewport's UI delegate.

Parameters:
ui - The viewport's UI delegate.


setView

public void setView(Component v)


setViewPosition

public void setViewPosition(Point p)


setViewSize

public void setViewSize(Dimension newSize)


toViewCoordinates

public Dimension toViewCoordinates(Dimension size)


toViewCoordinates

public Point toViewCoordinates(Point p)


updateUI

public void updateUI()
This method resets the UI used to the Look and Feel defaults..
Overrides:
updateUI in interface JComponent


JViewport.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.