JViewport (Java 2 Platform SE 5.0) (original) (raw)
javax.swing
Class JViewport
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, JViewport
is opaque. To change this, use thesetOpaque
method.
**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 acopyArea
on 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.
In general this approach is much faster. Compared to the backing store approach this avoids the overhead of maintaining an offscreen buffer and having to do two
copyArea
s. 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: 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 JavaBeansTM has been added to the java.beans
package. Please see XMLEncoder.
See Also:
Nested Class Summary | |
---|---|
protected class | JViewport.AccessibleJViewport This class implements accessibility support for the JViewport class. |
protected class | JViewport.ViewListener A listener for the view. |
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 | |
---|---|
protected boolean | backingStore Deprecated. As of Java 2 platform v1.3 |
static int | BACKINGSTORE_SCROLL_MODE Draws viewport contents into an offscreen image. |
protected Image | backingStoreImage The view image used for a backing store. |
static int | BLIT_SCROLL_MODE Use graphics.copyArea to implement scrolling. |
protected boolean | isViewSizeSet True when the viewport dimensions have been determined. |
protected 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 likeJList. |
static int | SIMPLE_SCROLL_MODE This mode uses the very simple method of redrawing the entire contents of the scrollpane each time it is scrolled. |
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 |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary |
---|
JViewport() Creates a JViewport. |
Method Summary | |
---|---|
void | addChangeListener(ChangeListener l) Adds a ChangeListener to the list that is notified each time the view's size, position, or the viewport's extent size has changed. |
protected void | [addImpl](../../javax/swing/JViewport.html#addImpl%28java.awt.Component, java.lang.Object, int%29)(Component child,Object constraints, int index) Sets the JViewport's one lightweight child, which can be null. |
protected boolean | [computeBlit](../../javax/swing/JViewport.html#computeBlit%28int, int, java.awt.Point, java.awt.Point, java.awt.Dimension, java.awt.Rectangle%29)(int dx, int dy,Point blitFrom,Point blitTo,Dimension blitSize,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 LayoutManager | createLayoutManager() Subclassers can override this to install a different layout manager (or null) in the constructor. |
protected JViewport.ViewListener | createViewListener() Creates a listener for the view. |
protected void | [firePropertyChange](../../javax/swing/JViewport.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29)(String propertyName,Object oldValue,Object newValue) Notifies listeners of a property change. |
protected void | fireStateChanged() Notifies all ChangeListeners when the views size, position, or the viewports extent size has changed. |
AccessibleContext | getAccessibleContext() Gets the AccessibleContext associated with this JViewport. |
ChangeListener[] | getChangeListeners() Returns an array of all the ChangeListeners added to this JViewport with addChangeListener(). |
Dimension | getExtentSize() Returns the size of the visible part of the view in view coordinates. |
Insets | getInsets() Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on a JViewport. |
Insets | getInsets(Insets insets) Returns an Insets object containing thisJViewports inset values. |
int | getScrollMode() Returns the current scrolling mode. |
ViewportUI | getUI() Returns the L&F object that renders this component. |
String | getUIClassID() Returns a string that specifies the name of the L&F class that renders this component. |
Component | getView() Returns the JViewport's one child or null. |
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. |
Rectangle | getViewRect() Returns a rectangle whose origin is getViewPosition and size is getExtentSize. |
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() Deprecated. As of Java 2 platform v1.3, replaced bygetScrollMode(). |
boolean | isOptimizedDrawingEnabled() The JViewport overrides the default implementation of this method (in JComponent) to return false. |
void | paint(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 String | paramString() Returns a string representation of this JViewport. |
void | remove(Component child) Removes the Viewports one lightweight child. |
void | removeChangeListener(ChangeListener l) Removes a ChangeListener from the list that's notified each time the views size, position, or the viewports extent size has changed. |
void | [repaint](../../javax/swing/JViewport.html#repaint%28long, int, int, int, int%29)(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 the RepaintManager. |
void | [reshape](../../javax/swing/JViewport.html#reshape%28int, int, int, int%29)(int x, int y, int w, int h) Sets the bounds of this viewport. |
void | scrollRectToVisible(Rectangle contentRect) Scrolls the view so that Rectangle within the view becomes visible. |
void | setBackingStoreEnabled(boolean enabled) Deprecated. As of Java 2 platform v1.3, replaced bysetScrollMode(). |
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). |
void | setExtentSize(Dimension newExtent) Sets the size of the visible part of the view using view coordinates. |
void | setScrollMode(int mode) Used to control the method of scrolling the viewport contents. |
void | setUI(ViewportUI ui) Sets the L&F object that renders this component. |
void | setView(Component view) Sets the JViewport's one lightweight child (view), which can be null. |
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. |
void | setViewSize(Dimension newSize) Sets the size of the view. |
Dimension | toViewCoordinates(Dimension size) Converts a size in pixel coordinates to view coordinates. |
Point | toViewCoordinates(Point p) Converts a point in pixel coordinates to view coordinates. |
void | updateUI() Resets the UI property to a value from the current look and feel. |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, [contains](../../javax/swing/JComponent.html#contains%28int, int%29), createToolTip, disable, enable, [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, int, int%29), [fireVetoableChange](../../javax/swing/JComponent.html#fireVetoableChange%28java.lang.String, java.lang.Object, java.lang.Object%29), getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, [paintImmediately](../../javax/swing/JComponent.html#paintImmediately%28int, int, int, int%29), paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, [processKeyBinding](../../javax/swing/JComponent.html#processKeyBinding%28javax.swing.KeyStroke, java.awt.event.KeyEvent, int, boolean%29), processKeyEvent, processMouseEvent, processMouseMotionEvent, [putClientProperty](../../javax/swing/JComponent.html#putClientProperty%28java.lang.Object, java.lang.Object%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, javax.swing.KeyStroke, int%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int%29), removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, [setFocusTraversalKeys](../../javax/swing/JComponent.html#setFocusTraversalKeys%28int, java.util.Set%29), setFont, setForeground, setInheritsPopupMenu, [setInputMap](../../javax/swing/JComponent.html#setInputMap%28int, javax.swing.InputMap%29), setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, [add](../../java/awt/Container.html#add%28java.awt.Component, int%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object, int%29), [add](../../java/awt/Container.html#add%28java.lang.String, java.awt.Component%29), addContainerListener, addPropertyChangeListener, [addPropertyChangeListener](../../java/awt/Container.html#addPropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, [findComponentAt](../../java/awt/Container.html#findComponentAt%28int, int%29), findComponentAt, getComponent, [getComponentAt](../../java/awt/Container.html#getComponentAt%28int, int%29), getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, [list](../../java/awt/Container.html#list%28java.io.PrintStream, int%29), [list](../../java/awt/Container.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Container.html#locate%28int, int%29), minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, [setComponentZOrder](../../java/awt/Container.html#setComponentZOrder%28java.awt.Component, int%29), setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, hide, [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29), [inside](../../java/awt/Component.html#inside%28int, int%29), isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), list, list, list, location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paintAll, postEvent, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, resize, [resize](../../java/awt/Component.html#resize%28int, int%29), [setBounds](../../java/awt/Component.html#setBounds%28int, int, int, int%29), setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setName, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Field Detail |
---|
isViewSizeSet
protected boolean isViewSizeSet
True when the viewport dimensions have been determined. The default is false.
lastPaintPosition
protected Point lastPaintPosition
The last viewPosition
that 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.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. The default is false
.
See Also:
backingStoreImage
protected transient Image backingStoreImage
The view image used for a backing store.
scrollUnderway
protected boolean scrollUnderway
The scrollUnderway
flag is used for components likeJList
. When the downarrow key is pressed on aJList
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 optimized painting only when there is an explicit call tosetViewPosition(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 JViewport
class and have the JList
manage this case by usingsetBackingStoreEnabled
. The default isfalse
.
BLIT_SCROLL_MODE
public static final int BLIT_SCROLL_MODE
Use graphics.copyArea
to implement scrolling. This is the fastest for most applications.
Since:
1.3
See Also:
setScrollMode(int), Constant Field Values
BACKINGSTORE_SCROLL_MODE
public static final int BACKINGSTORE_SCROLL_MODE
Draws viewport contents into an offscreen image. This was previously the default mode for JTable
. 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_MODE
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. 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
Constructor Detail |
---|
JViewport
public JViewport()
Creates a JViewport
.
Method Detail |
---|
getUI
public ViewportUI getUI()
Returns the L&F object that renders this component.
Returns:
a ViewportUI
object
setUI
public void setUI(ViewportUI ui)
Sets the L&F object that renders this component.
Parameters:
ui
- the ViewportUI
L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)
updateUI
public void updateUI()
Resets the UI property to a value from the current look and feel.
Overrides:
[updateUI](../../javax/swing/JComponent.html#updateUI%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
See Also:
getUIClassID
public String getUIClassID()
Returns a string that specifies the name of the L&F class that renders this component.
Overrides:
[getUIClassID](../../javax/swing/JComponent.html#getUIClassID%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
the string "ViewportUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)
addImpl
protected void addImpl(Component child, Object constraints, int index)
Sets the JViewport
'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.)
Overrides:
[addImpl](../../java/awt/Container.html#addImpl%28java.awt.Component, java.lang.Object, int%29)
in class [Container](../../java/awt/Container.html "class in java.awt")
Parameters:
child
- the lightweight child
of the viewport
constraints
- the constraints
to be respected
index
- the index
See Also:
remove
public void remove(Component child)
Removes the Viewport
s one lightweight child.
Overrides:
[remove](../../java/awt/Container.html#remove%28java.awt.Component%29)
in class [Container](../../java/awt/Container.html "class in java.awt")
Parameters:
child
- the component to be removed
See Also:
scrollRectToVisible
public void scrollRectToVisible(Rectangle contentRect)
Scrolls the view so that Rectangle
within the view becomes visible.
This attempts to validate the view before scrolling if the view is currently not valid - isValid
returns 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 a Window
or Applet
.
Note that this method will not scroll outside of the valid viewport; for example, if contentRect
is larger than the viewport, scrolling will be confined to the viewport's bounds.
Overrides:
[scrollRectToVisible](../../javax/swing/JComponent.html#scrollRectToVisible%28java.awt.Rectangle%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Parameters:
contentRect
- the Rectangle
to display
See Also:
JComponent.isValidateRoot(), Component.isValid(), Component.getPeer()
setBorder
public 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-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.
Note: If border
is non-null
, this method will throw an exception as borders are not supported on a JViewPort
.
Overrides:
[setBorder](../../javax/swing/JComponent.html#setBorder%28javax.swing.border.Border%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Parameters:
border
- the Border
to set
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- this method is not implemented
See Also:
getInsets
public final Insets getInsets()
Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on a JViewport
.
Overrides:
[getInsets](../../javax/swing/JComponent.html#getInsets%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
a Rectange
of zero dimension and zero origin
See Also:
setBorder(javax.swing.border.Border)
getInsets
public final Insets getInsets(Insets insets)
Returns an Insets
object containing thisJViewport
s inset values. The passed-inInsets
object will be reinitialized, and all existing values within this object are overwritten.
Overrides:
[getInsets](../../javax/swing/JComponent.html#getInsets%28java.awt.Insets%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Parameters:
insets
- the Insets
object which can be reused
Returns:
this viewports inset values
See Also:
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
'spaint
implementation rather than messaging the JViewport
's children directly.
Overrides:
[isOptimizedDrawingEnabled](../../javax/swing/JComponent.html#isOptimizedDrawingEnabled%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
false
paint
public void paint(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.)
Overrides:
[paint](../../javax/swing/JComponent.html#paint%28java.awt.Graphics%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Parameters:
g
- the Graphics
context 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)](../../javax/swing/JComponent.html#repaint%28long, int, int, int, int%29)
reshape
public 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 a StateChanged
event.
Overrides:
[reshape](../../javax/swing/JComponent.html#reshape%28int, int, int, int%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
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)](../../javax/swing/JComponent.html#reshape%28int, int, int, int%29)
setScrollMode
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
getScrollMode
public int getScrollMode()
Returns the current scrolling mode.
Returns:
the scrollMode
property
Since:
1.3
See Also:
isBackingStoreEnabled
@Deprecated public boolean isBackingStoreEnabled()
Deprecated. As of Java 2 platform v1.3, replaced bygetScrollMode()
.
Returns true
if this viewport is maintaining an offscreen image of its contents.
Returns:
true
if scrollMode
isBACKINGSTORE_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 the viewPosition
. Rather than repainting the entire viewport we useGraphics.copyArea
to effect some of the scroll.
Parameters:
enabled
- if true, maintain an offscreen backing store
getView
public Component getView()
Returns the JViewport
's one child or null
.
Returns:
the viewports child, or null
if none exists
See Also:
setView
public void setView(Component view)
Sets the JViewport
's one lightweight child (view
), which can be null
.
Parameters:
view
- the viewport's new lightweight child
See Also:
getViewSize
public 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(Dimension newSize)
Sets the size of the view. A state changed event will be fired.
Parameters:
newSize
- a Dimension
object specifying the new size of the view
getViewPosition
public 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 Point
object giving the upper left coordinates
setViewPosition
public 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 Point
object giving the upper left coordinates
getViewRect
public Rectangle getViewRect()
Returns 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, Point blitFrom, Point blitTo, Dimension blitSize, 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.
Parameters:
dx
- the horizontal delta
dy
- the vertical delta
blitFrom
- the Point
we're blitting from
blitTo
- the Point
we're blitting to
blitSize
- the Dimension
of the area to blit
blitPaint
- the area to blit
Returns:
true if the parameters are modified and we're ready to blit; false otherwise
getExtentSize
public 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 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 Dimension
object using pixel coordinates
Returns:
a Dimension
object converted to view coordinates
toViewCoordinates
public 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 Point
object using pixel coordinates
Returns:
a Point
object converted to view coordinates
setExtentSize
public void setExtentSize(Dimension newExtent)
Sets 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()
Creates a listener for the view.
Returns:
a ViewListener
createLayoutManager
protected LayoutManager createLayoutManager()
Subclassers can override this to install a different layout manager (or null
) in the constructor. Returns the LayoutManager
to install on the JViewport
.
Returns:
a LayoutManager
addChangeListener
public void addChangeListener(ChangeListener l)
Adds a ChangeListener
to the list that is 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)
Removes 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)
getChangeListeners
public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListener
s added to this JViewport with addChangeListener().
Returns:
all of the ChangeListener
s added or an empty array if no listeners have been added
Since:
1.4
fireStateChanged
protected void fireStateChanged()
Notifies all ChangeListeners
when the views size, position, or the viewports extent size has changed.
See Also:
addChangeListener(javax.swing.event.ChangeListener), removeChangeListener(javax.swing.event.ChangeListener), EventListenerList
repaint
public 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 the RepaintManager
.
Overrides:
[repaint](../../javax/swing/JComponent.html#repaint%28long, int, int, int, int%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Parameters:
tm
- maximum time in milliseconds before update
x
- the x
coordinate (pixels over from left)
y
- the y
coordinate (pixels down from top)
w
- the width
h
- the height
See Also:
Component.update(java.awt.Graphics)
paramString
protected 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
.
Overrides:
[paramString](../../javax/swing/JComponent.html#paramString%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
a string representation of this JViewport
firePropertyChange
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
Notifies listeners of a property change. This is subclassed to update the windowBlit
property. (The putClientProperty
property is final).
Overrides:
[firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29)
in class [Component](../../java/awt/Component.html "class in java.awt")
Parameters:
propertyName
- a string containing the property name
oldValue
- the old value of the property
newValue
- the new value of the property
getAccessibleContext
public 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:
[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext%28%29)
in interface [Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")
Overrides:
[getAccessibleContext](../../javax/swing/JComponent.html#getAccessibleContext%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
an AccessibleJViewport that serves as the AccessibleContext of this JViewport
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.