RepaintManager (Java Platform SE 8 ) (original) (raw)
- javax.swing.RepaintManager
public class RepaintManager
extends Object
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 (JApplet
,JWindow
, JFrame
and JDialog
). Any calls to repaint
on one of these will call into the appropriate addDirtyRegion
method.
Constructor Summary
Constructors
Constructor Description RepaintManager() Create a new RepaintManager instance. Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method Description void addDirtyRegion(Applet applet, int x, int y, int w, int h) Adds applet to the list of Components that need to be repainted. void addDirtyRegion(JComponent c, int x, int y, int w, int h) Add a component in the list of components that should be refreshed. void addDirtyRegion(Window window, int x, int y, int w, int h) Adds window to the list of Components that need to be repainted. void addInvalidComponent(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 RepaintManager currentManager(Component c) Return the RepaintManager for the calling thread given a Component. static RepaintManager currentManager(JComponent c) Return the RepaintManager for the calling thread given a JComponent. Rectangle getDirtyRegion(JComponent aComponent) Return the current dirty region for a component. Dimension getDoubleBufferMaximumSize() Returns the maximum double buffer size. Image getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) Return the offscreen buffer that should be used as a double buffer with the component c. Image getVolatileOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) Return a volatile offscreen buffer that should be used as a double buffer with the specified component c. boolean isCompletelyDirty(JComponent aComponent) Convenience method that returns true if aComponent will be completely painted during the next paintDirtyRegions(). boolean isDoubleBufferingEnabled() Returns true if this RepaintManager is double buffered. void markCompletelyClean(JComponent aComponent) Mark a component completely clean. void markCompletelyDirty(JComponent aComponent) Mark a component completely dirty. void paintDirtyRegions() Paint all of the components that have been marked dirty. void removeInvalidComponent(JComponent component) Remove a component from the list of invalid components. static void setCurrentManager(RepaintManager aRepaintManager) Set the RepaintManager that should be used for the calling thread. void setDoubleBufferingEnabled(boolean aFlag) Enables or disables double buffering in this RepaintManager. void setDoubleBufferMaximumSize(Dimension d) Set the maximum double buffer size. String toString() Returns a string that displays and identifies this object's properties. void validateInvalidComponents() Validate all of the components that have been marked invalid. * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[clone](../../java/lang/Object.html#clone--), [equals](../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../java/lang/Object.html#finalize--), [getClass](../../java/lang/Object.html#getClass--), [hashCode](../../java/lang/Object.html#hashCode--), [notify](../../java/lang/Object.html#notify--), [notifyAll](../../java/lang/Object.html#notifyAll--), [wait](../../java/lang/Object.html#wait--), [wait](../../java/lang/Object.html#wait-long-), [wait](../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### 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 Detail
* #### currentManager public static [RepaintManager](../../javax/swing/RepaintManager.html "class in javax.swing") currentManager([Component](../../java/awt/Component.html "class in java.awt") c) Return the RepaintManager for the calling thread 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 public static [RepaintManager](../../javax/swing/RepaintManager.html "class in javax.swing") currentManager([JComponent](../../javax/swing/JComponent.html "class in javax.swing") c) 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)](../../javax/swing/RepaintManager.html#currentManager-java.awt.Component-). Parameters: `c` \- a JComponent -- unused Returns: the RepaintManager object * #### setCurrentManager public static void setCurrentManager([RepaintManager](../../javax/swing/RepaintManager.html "class in javax.swing") aRepaintManager) Set the RepaintManager that should be used for the calling thread. **aRepaintManager** will become the current RepaintManager for the calling thread's thread group. Parameters: `aRepaintManager` \- the RepaintManager object to use * #### addInvalidComponent public void addInvalidComponent([JComponent](../../javax/swing/JComponent.html "class in javax.swing") 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. See Also: [JComponent.isValidateRoot()](../../javax/swing/JComponent.html#isValidateRoot--), [removeInvalidComponent(javax.swing.JComponent)](../../javax/swing/RepaintManager.html#removeInvalidComponent-javax.swing.JComponent-) * #### removeInvalidComponent public void removeInvalidComponent([JComponent](../../javax/swing/JComponent.html "class in javax.swing") component) Remove a component from the list of invalid components. See Also: [addInvalidComponent(javax.swing.JComponent)](../../javax/swing/RepaintManager.html#addInvalidComponent-javax.swing.JComponent-) * #### addDirtyRegion public void addDirtyRegion([JComponent](../../javax/swing/JComponent.html "class in javax.swing") c, int x, int y, int w, int h) 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 repaint `y` \- Y coordinate of the region to repaint `w` \- Width of the region to repaint `h` \- Height of the region to repaint See Also: [JComponent.repaint(long, int, int, int, int)](../../javax/swing/JComponent.html#repaint-long-int-int-int-int-) * #### addDirtyRegion public void addDirtyRegion([Window](../../java/awt/Window.html "class in java.awt") window, int x, int y, int w, int h) Adds `window` to the list of `Component`s that need to be repainted. Parameters: `window` \- Window to repaint, null results in nothing happening. `x` \- X coordinate of the region to repaint `y` \- Y coordinate of the region to repaint `w` \- Width of the region to repaint `h` \- Height of the region to repaint Since: 1.6 See Also: [JFrame.repaint(long, int, int, int, int)](../../javax/swing/JFrame.html#repaint-long-int-int-int-int-), [JWindow.repaint(long, int, int, int, int)](../../javax/swing/JWindow.html#repaint-long-int-int-int-int-), [JDialog.repaint(long, int, int, int, int)](../../javax/swing/JDialog.html#repaint-long-int-int-int-int-) * #### addDirtyRegion public void addDirtyRegion([Applet](../../java/applet/Applet.html "class in java.applet") applet, int x, int y, int w, int h) Adds `applet` to the list of `Component`s that need to be repainted. Parameters: `applet` \- Applet to repaint, null results in nothing happening. `x` \- X coordinate of the region to repaint `y` \- Y coordinate of the region to repaint `w` \- Width of the region to repaint `h` \- Height of the region to repaint Since: 1.6 See Also: [JApplet.repaint(long, int, int, int, int)](../../javax/swing/JApplet.html#repaint-long-int-int-int-int-) * #### getDirtyRegion public [Rectangle](../../java/awt/Rectangle.html "class in java.awt") getDirtyRegion([JComponent](../../javax/swing/JComponent.html "class in javax.swing") aComponent) Return the current dirty region for a component. Return an empty rectangle if the component is not dirty. * #### markCompletelyDirty public void markCompletelyDirty([JComponent](../../javax/swing/JComponent.html "class in javax.swing") aComponent) Mark a component completely dirty. **aComponent** will be completely painted during the next paintDirtyRegions() call. * #### markCompletelyClean public void markCompletelyClean([JComponent](../../javax/swing/JComponent.html "class in javax.swing") aComponent) Mark a component completely clean. **aComponent** will not get painted during the next paintDirtyRegions() call. * #### isCompletelyDirty public boolean isCompletelyDirty([JComponent](../../javax/swing/JComponent.html "class in javax.swing") aComponent) 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. * #### validateInvalidComponents public void validateInvalidComponents() Validate all of the components that have been marked invalid. See Also: [addInvalidComponent(javax.swing.JComponent)](../../javax/swing/RepaintManager.html#addInvalidComponent-javax.swing.JComponent-) * #### paintDirtyRegions public void paintDirtyRegions() Paint all of the components that have been marked dirty. See Also: [addDirtyRegion(javax.swing.JComponent, int, int, int, int)](../../javax/swing/RepaintManager.html#addDirtyRegion-javax.swing.JComponent-int-int-int-int-) * #### toString public [String](../../java/lang/String.html "class in java.lang") toString() Returns a string that displays and identifies this object's properties. Overrides: `[toString](../../java/lang/Object.html#toString--)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Returns: a String representation of this object * #### getOffscreenBuffer public [Image](../../java/awt/Image.html "class in java.awt") getOffscreenBuffer([Component](../../java/awt/Component.html "class in java.awt") c, int proposedWidth, int proposedHeight) Return the offscreen buffer that should be used as a double buffer with the component `c`. 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. * #### getVolatileOffscreenBuffer public [Image](../../java/awt/Image.html "class in java.awt") getVolatileOffscreenBuffer([Component](../../java/awt/Component.html "class in java.awt") c, int proposedWidth, int proposedHeight) Return a volatile offscreen buffer that should be used as a double buffer with the specified component `c`. 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. Since: 1.4 See Also: [VolatileImage](../../java/awt/image/VolatileImage.html "class in java.awt.image") * #### setDoubleBufferMaximumSize public void setDoubleBufferMaximumSize([Dimension](../../java/awt/Dimension.html "class in java.awt") d) Set the maximum double buffer size. * #### getDoubleBufferMaximumSize public [Dimension](../../java/awt/Dimension.html "class in java.awt") 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()](../../javax/swing/RepaintManager.html#isDoubleBufferingEnabled--) * #### 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 be `false` to avoid unnecessary buffering in Swing. On platforms where native double buffering is not supported, the default value will be `true`. Returns: true if this object is double buffered
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.