public class JViewport extends JComponent implements Accessible
_ +-------------------------------+ ...........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)
Modifier and Type | Class and Description |
---|---|
protected class |
JViewport.AccessibleJViewport
Provides accessibility support for
JViewport . |
protected class |
JViewport.ViewListener
A
ComponentListener that listens for
changes of the view's size. |
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected boolean |
backingStore
Deprecated.
since JDK 1.3
|
static int |
BACKINGSTORE_SCROLL_MODE |
protected Image |
backingStoreImage
The backingstore image used for the backingstore and blit scroll methods.
|
static int |
BLIT_SCROLL_MODE |
protected boolean |
isViewSizeSet |
protected Point |
lastPaintPosition
The position at which the view has been drawn the last time.
|
protected boolean |
scrollUnderway |
static int |
SIMPLE_SCROLL_MODE |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JViewport() |
Modifier and Type | Method and Description |
---|---|
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 boolean |
computeBlit(int dx,
int dy,
Point blitFrom,
Point blitTo,
Dimension blitSize,
Rectangle blitPaint)
Computes the parameters for the blitting scroll method.
|
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() |
AccessibleContext |
getAccessibleContext()
Returns the accessible context for this
JViewport . |
ChangeListener[] |
getChangeListeners() |
Dimension |
getExtentSize() |
Insets |
getInsets()
Get the component's insets, which are calculated from
the
JComponent.border property. |
Insets |
getInsets(Insets insets)
Get the component's insets, which are calculated from the
JComponent.border 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()
Overridden to return
false , so the JViewport's paint method
gets called instead of directly calling the children. |
void |
paint(Graphics g)
Paint the component.
|
void |
removeChangeListener(ChangeListener listener) |
void |
repaint(long tm,
int x,
int y,
int w,
int h)
Forward repaint to parent to make sure only one paint is performed by the
RepaintManager.
|
void |
reshape(int x,
int y,
int w,
int h)
Moves and resizes the component.
|
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.border 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..
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, 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, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, 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, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, 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, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final int SIMPLE_SCROLL_MODE
public static final int BLIT_SCROLL_MODE
public static final int BACKINGSTORE_SCROLL_MODE
protected boolean scrollUnderway
protected boolean isViewSizeSet
protected boolean backingStore
protected Image backingStoreImage
protected Point lastPaintPosition
public JViewport()
public Dimension getExtentSize()
public Dimension toViewCoordinates(Dimension size)
public Point toViewCoordinates(Point p)
public void setExtentSize(Dimension newSize)
public Dimension getViewSize()
public void setViewSize(Dimension newSize)
public Point getViewPosition()
public void setViewPosition(Point p)
public Rectangle getViewRect()
public boolean isBackingStoreEnabled()
public void setBackingStoreEnabled(boolean b)
public void setScrollMode(int mode)
public int getScrollMode()
public void reshape(int x, int y, int w, int h)
JComponent
reshape
in class JComponent
x
- the new horizontal locationy
- the new vertial locationw
- the new widthh
- the new heightpublic final Insets getInsets()
JComponent
JComponent.border
property. If the border is null
,
calls Container.getInsets()
.getInsets
in class JComponent
public final Insets getInsets(Insets insets)
JComponent
JComponent.border
property. If the border is null
, calls Container.getInsets()
. The passed-in Insets
value will be
used as the return value, if possible.getInsets
in class JComponent
insets
- Return value object to reuse, if possiblepublic boolean isOptimizedDrawingEnabled()
false
, so the JViewport's paint method
gets called instead of directly calling the children. This is necessary
in order to get a useful clipping and translation on the children.isOptimizedDrawingEnabled
in class JComponent
false
public void paint(Graphics g)
JComponent
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 Component.repaint()
to
trigger painting.
The body of the paint
call involves calling JComponent.paintComponent(java.awt.Graphics)
, JComponent.paintBorder(java.awt.Graphics)
, and JComponent.paintChildren(java.awt.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.
paint
in class JComponent
g
- The graphics context to paint withJComponent.paintImmediately(Rectangle)
public void addChangeListener(ChangeListener listener)
public void removeChangeListener(ChangeListener listener)
public ChangeListener[] getChangeListeners()
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public void updateUI()
updateUI
in class JComponent
public ViewportUI getUI()
public void setUI(ViewportUI ui)
ui
- The viewport's UI delegate.public final void setBorder(Border border)
JComponent
JComponent.border
property.setBorder
in class JComponent
border
- The new value of the propertyJComponent.getBorder()
public void scrollRectToVisible(Rectangle contentRect)
scrollRectToVisible
in class JComponent
contentRect
- the rectangle to make visible within the viewpublic AccessibleContext getAccessibleContext()
JViewport
. This
will be an instance of JViewport.AccessibleJViewport
.getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
JViewport
public void repaint(long tm, int x, int y, int w, int h)
repaint
in class JComponent
tm
- number of milliseconds to defer the repaint requestx
- the X coordinate of the upper left corner of the dirty areay
- the Y coordinate of the upper left corner of the dirty areaw
- the width of the dirty areah
- the height of the dirty areaComponent.update(Graphics)
protected void addImpl(Component comp, Object constraints, int index)
Container
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.protected void fireStateChanged()
protected JViewport.ViewListener createViewListener()
JViewport.ViewListener
that is supposed to listen for
size changes on the view component.protected LayoutManager createLayoutManager()
protected boolean computeBlit(int dx, int dy, Point blitFrom, Point blitTo, Dimension blitSize, Rectangle blitPaint)
dx
and dy
specifiy the X and Y offset by which the viewport
is scrolled. All other arguments are output parameters and are filled by
this method.
blitFrom
holds the position of the blit rectangle in the
viewport rectangle before scrolling, blitTo
where the blitArea
is copied to.
blitSize
holds the size of the blit area and
blitPaint
is the area of the view that needs to be painted.
This method returns true
if blitting is possible and
false
if the viewport has to be repainted completetly without
blitting.dx
- the horizontal deltady
- the vertical deltablitFrom
- the position from where to blit; set by this methodblitTo
- the position where to blit area is copied to; set by this
methodblitSize
- the size of the blitted area; set by this methodblitPaint
- the area that needs repainting; set by this methodtrue
if blitting is possible,
false
otherwise