Class RepaintManager
java.lang.Object
javax.swing.RepaintManager
This class manages repaint requests, allowing the number
of repaints to be minimized, for example by collapsing multiple
requests into a single repaint for members of a component tree.
As of 1.6 RepaintManager handles repaint requests
for Swing's top level components
(JWindow, JFrame and JDialog).
Any calls to repaint on one of these will call into the
appropriate addDirtyRegion method.
- Since:
- 1.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDirtyRegion(Window window, int x, int y, int w, int h) Addswindowto the list ofComponents that need to be repainted.voidaddDirtyRegion(JComponent c, int x, int y, int w, int h) Add a component in the list of components that should be refreshed.voidaddInvalidComponent(JComponent invalidComponent) Mark the component as in need of layout and queue a runnable for the event dispatching thread that will validate the components first isValidateRoot() ancestor.static RepaintManagerReturn the RepaintManager given a Component.static RepaintManagerReturn the RepaintManager for the calling thread given a JComponent.getDirtyRegion(JComponent aComponent) Return the current dirty region for a component.Returns the maximum double buffer size.getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) Return the offscreen buffer that should be used as a double buffer with the componentc.getVolatileOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) Return a volatile offscreen buffer that should be used as a double buffer with the specified componentc.booleanisCompletelyDirty(JComponent aComponent) Convenience method that returns true if aComponent will be completely painted during the next paintDirtyRegions().booleanReturns true if this RepaintManager is double buffered.voidmarkCompletelyClean(JComponent aComponent) Mark a component completely clean.voidmarkCompletelyDirty(JComponent aComponent) Mark a component completely dirty.voidPaint all of the components that have been marked dirty.voidremoveInvalidComponent(JComponent component) Remove a component from the list of invalid components.static voidsetCurrentManager(RepaintManager aRepaintManager) Set the RepaintManager.voidsetDoubleBufferingEnabled(boolean aFlag) Enables or disables double buffering in this RepaintManager.voidSet the maximum double buffer size.toString()Returns a string that displays and identifies this object's properties.voidValidate all of the components that have been marked invalid.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
RepaintManager
public RepaintManager()Create a new RepaintManager instance. You rarely call this constructor. directly. To get the default RepaintManager, use RepaintManager.currentManager(JComponent) (normally "this").
-
-
Method Details
-
currentManager
Return the RepaintManager given a Component.- Parameters:
c- a Component -- unused in the default implementation, but could be used by an overridden version to return a different RepaintManager depending on the Component- Returns:
- the RepaintManager object
-
currentManager
Return the RepaintManager for the calling thread given a JComponent.Note: This method exists for backward binary compatibility with earlier versions of the Swing library. It simply returns the result returned by
currentManager(Component).- Parameters:
c- a JComponent -- unused- Returns:
- the RepaintManager object
-
setCurrentManager
Set the RepaintManager.- Parameters:
aRepaintManager- the RepaintManager object to use
-
addInvalidComponent
Mark the component as in need of layout and queue a runnable for the event dispatching thread that will validate the components first isValidateRoot() ancestor.- Parameters:
invalidComponent- a component- See Also:
-
removeInvalidComponent
Remove a component from the list of invalid components.- Parameters:
component- a component- See Also:
-
addDirtyRegion
Add a component in the list of components that should be refreshed. If c already has a dirty region, the rectangle (x,y,w,h) will be unioned with the region that should be redrawn.- Parameters:
c- Component to repaint, null results in nothing happening.x- X coordinate of the region to repainty- Y coordinate of the region to repaintw- Width of the region to repainth- Height of the region to repaint- See Also:
-
addDirtyRegion
Addswindowto the list ofComponents that need to be repainted.- Parameters:
window- Window to repaint, null results in nothing happening.x- X coordinate of the region to repainty- Y coordinate of the region to repaintw- Width of the region to repainth- Height of the region to repaint- Since:
- 1.6
- See Also:
-
getDirtyRegion
Return the current dirty region for a component. Return an empty rectangle if the component is not dirty.- Parameters:
aComponent- a component- Returns:
- the region
-
markCompletelyDirty
Mark a component completely dirty. aComponent will be completely painted during the next paintDirtyRegions() call.- Parameters:
aComponent- a component
-
markCompletelyClean
Mark a component completely clean. aComponent will not get painted during the next paintDirtyRegions() call.- Parameters:
aComponent- a component
-
isCompletelyDirty
Convenience method that returns true if aComponent will be completely painted during the next paintDirtyRegions(). If computing dirty regions is expensive for your component, use this method and avoid computing dirty region if it return true.- Parameters:
aComponent- a component- Returns:
trueif aComponent will be completely painted during the next paintDirtyRegions().
-
validateInvalidComponents
public void validateInvalidComponents()Validate all of the components that have been marked invalid.- See Also:
-
paintDirtyRegions
public void paintDirtyRegions()Paint all of the components that have been marked dirty.- See Also:
-
toString
-
getOffscreenBuffer
Return the offscreen buffer that should be used as a double buffer with the componentc. By default there is a double buffer per RepaintManager. The buffer might be smaller than(proposedWidth,proposedHeight)This happens when the maximum double buffer size as been set for the receiving repaint manager.- Parameters:
c- the componentproposedWidth- the width of the bufferproposedHeight- the height of the buffer- Returns:
- the image
-
getVolatileOffscreenBuffer
Return a volatile offscreen buffer that should be used as a double buffer with the specified componentc. The image returned will be an instance of VolatileImage, or null if a VolatileImage object could not be instantiated. This buffer might be smaller than(proposedWidth,proposedHeight). This happens when the maximum double buffer size has been set for this repaint manager.- Parameters:
c- the componentproposedWidth- the width of the bufferproposedHeight- the height of the buffer- Returns:
- the volatile image
- Since:
- 1.4
- See Also:
-
setDoubleBufferMaximumSize
Set the maximum double buffer size.- Parameters:
d- the dimension
-
getDoubleBufferMaximumSize
Returns the maximum double buffer size.- Returns:
- a Dimension object representing the maximum size
-
setDoubleBufferingEnabled
public void setDoubleBufferingEnabled(boolean aFlag) Enables or disables double buffering in this RepaintManager. CAUTION: The default value for this property is set for optimal paint performance on the given platform and it is not recommended that programs modify this property directly.- Parameters:
aFlag- true to activate double buffering- See Also:
-
isDoubleBufferingEnabled
public boolean isDoubleBufferingEnabled()Returns true if this RepaintManager is double buffered. The default value for this property may vary from platform to platform. On platforms where native double buffering is supported in the AWT, the default value will befalseto avoid unnecessary buffering in Swing. On platforms where native double buffering is not supported, the default value will betrue.- Returns:
- true if this object is double buffered
-