JavaTM 2 Platform
Standard Ed. 6

javax.swing
类 RepaintManager

java.lang.Object
  继承者 javax.swing.RepaintManager

public class RepaintManager
extends Object

此类管理重绘请求,以最大限度地降低重绘次数。例如,通过将多个请求折叠到对组件树成员的单个重绘中。

从 1.6 开始,RepaintManager 处理对 Swing 的顶层组件(JAppletJWindowJFrameJDialog)的重绘请求。在这些组件之一上对 repaint 的任何调用将生成适当的 addDirtyRegion 方法。


构造方法摘要
RepaintManager()
          创建新的 RepaintManager 实例。
 
方法摘要
 void addDirtyRegion(Applet applet, int x, int y, int w, int h)
          将 applet 添加到需要重绘的 Component 列表。
 void addDirtyRegion(JComponent c, int x, int y, int w, int h)
          在应刷新的组件列表中添加组件。
 void addDirtyRegion(Window window, int x, int y, int w, int h)
          将 window 添加到需要重绘的 Component 列表。
 void addInvalidComponent(JComponent invalidComponent)
          按照布局需要标记组件,并将事件指派线程的 runnable 排入队列,该线程将验证组件的第一个 isValidateRoot() 祖先。
static RepaintManager currentManager(Component c)
          在给定 Component 的情况下,返回调用线程的 RepaintManager。
static RepaintManager currentManager(JComponent c)
          在给定 JComponent 的情况下,返回调用线程的 RepaintManager。
 Rectangle getDirtyRegion(JComponent aComponent)
          返回组件的当前脏区。
 Dimension getDoubleBufferMaximumSize()
          返回最大双缓冲区大小。
 Image getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight)
          返回屏幕外缓冲区,它应用作带有组件 c 的双缓冲区。
 Image getVolatileOffscreenBuffer(Component c, int proposedWidth, int proposedHeight)
          返回可变屏幕外缓冲区,它应用作带有指定组件 c 的双缓冲区。
 boolean isCompletelyDirty(JComponent aComponent)
          在下一个 paintDirtyRegions() 中全部绘制 aComponent 时返回 true 的便捷方法。
 boolean isDoubleBufferingEnabled()
          如果此 RepaintManager 被双缓冲,则返回 true。
 void markCompletelyClean(JComponent aComponent)
          标记完全干净的组件。
 void markCompletelyDirty(JComponent aComponent)
          标记完全弄脏的组件。
 void paintDirtyRegions()
          绘制被标记为脏的所有组件。
 void removeInvalidComponent(JComponent component)
          从无效组件的列表移除组件。
static void setCurrentManager(RepaintManager aRepaintManager)
          设置用于调用线程的 RepaintManager。
 void setDoubleBufferingEnabled(boolean aFlag)
          在此 RepaintManager 中,启用或禁用双缓冲。
 void setDoubleBufferMaximumSize(Dimension d)
          设置最大双缓冲区大小。
 String toString()
          返回一个显示并标记此对象属性的字符串。
 void validateInvalidComponents()
          验证被标记为无效的所有组件。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

RepaintManager

public RepaintManager()
创建新的 RepaintManager 实例。很少直接调用此构造方法。要获取默认 RepaintManager,请使用 RepaintManager.currentManager(JComponent)(通常为 "this")。

方法详细信息

currentManager

public static RepaintManager currentManager(Component c)
在给定 Component 的情况下,返回调用线程的 RepaintManager。

参数:
c - 在默认实现中未使用的 Component,但是重写版本可以使用它,以根据 Component 返回不同的 RepaintManager
返回:
RepaintManager 对象

currentManager

public static RepaintManager currentManager(JComponent c)
在给定 JComponent 的情况下,返回调用线程的 RepaintManager。

注:此方法用于与 Swing 库早期版本的向后二进制兼容性。它只返回 currentManager(Component) 返回的结果。

参数:
c - 未使用的 JComponent
返回:
RepaintManager 对象

setCurrentManager

public static void setCurrentManager(RepaintManager aRepaintManager)
设置用于调用线程的 RepaintManager。aRepaintManager 将成为调用线程的线程组的当前 RepaintManager。

参数:
aRepaintManager - 要使用的 RepaintManager 对象

addInvalidComponent

public void addInvalidComponent(JComponent invalidComponent)
按照布局需要标记组件,并将事件指派线程的 runnable 排入队列,该线程将验证组件的第一个 isValidateRoot() 祖先。

另请参见:
JComponent.isValidateRoot(), removeInvalidComponent(javax.swing.JComponent)

removeInvalidComponent

public void removeInvalidComponent(JComponent component)
从无效组件的列表移除组件。

另请参见:
addInvalidComponent(javax.swing.JComponent)

addDirtyRegion

public void addDirtyRegion(JComponent c,
                           int x,
                           int y,
                           int w,
                           int h)
在应刷新的组件列表中添加组件。如果 c 已有脏区 (dirty region),则矩形 (x,y,w,h) 将与应重绘的区域合并。

参数:
c - 要重绘的组件,null 不执行任何操作。
x - 要重绘区域的 X 坐标
y - 要重绘区域的 Y 坐标
w - 要重绘区域的宽度
h - 要重绘区域的高度
另请参见:
JComponent.repaint(long, int, int, int, int)

addDirtyRegion

public void addDirtyRegion(Window window,
                           int x,
                           int y,
                           int w,
                           int h)
window 添加到需要重绘的 Component 列表。

参数:
window - 要重绘的窗口,null 不执行任何操作。
x - 要重绘区域的 X 坐标
y - 要重绘区域的 Y 坐标
w - 要重绘区域的宽度
h - 要重绘区域的高度
从以下版本开始:
1.6
另请参见:
JFrame.repaint(long, int, int, int, int), JWindow.repaint(long, int, int, int, int), JDialog.repaint(long, int, int, int, int)

addDirtyRegion

public void addDirtyRegion(Applet applet,
                           int x,
                           int y,
                           int w,
                           int h)
applet 添加到需要重绘的 Component 列表。

参数:
applet - 要重绘的 Applet,null 不执行任何操作。
x - 要重绘区域的 X 坐标
y - 要重绘区域的 Y 坐标
w - 要重绘区域的宽度
h - 要重绘区域的高度
从以下版本开始:
1.6
另请参见:
JApplet.repaint(long, int, int, int, int)

getDirtyRegion

public Rectangle getDirtyRegion(JComponent aComponent)
返回组件的当前脏区。如果组件不脏,则返回空矩形。


markCompletelyDirty

public void markCompletelyDirty(JComponent aComponent)
标记完全弄脏的组件。在下一个 paintDirtyRegions() 调用中,将全部绘制 aComponent


markCompletelyClean

public void markCompletelyClean(JComponent aComponent)
标记完全干净的组件。在下一个 paintDirtyRegions() 调用中,将不绘制 aComponent


isCompletelyDirty

public boolean isCompletelyDirty(JComponent aComponent)
在下一个 paintDirtyRegions() 中全部绘制 aComponent 时返回 true 的便捷方法。如果计算脏区对组件开销很大,请使用此方法,避免在其返回 true 时计算脏区。


validateInvalidComponents

public void validateInvalidComponents()
验证被标记为无效的所有组件。

另请参见:
addInvalidComponent(javax.swing.JComponent)

paintDirtyRegions

public void paintDirtyRegions()
绘制被标记为脏的所有组件。

另请参见:
addDirtyRegion(javax.swing.JComponent, int, int, int, int)

toString

public String toString()
返回一个显示并标记此对象属性的字符串。

覆盖:
Object 中的 toString
返回:
此对象的字符串表示形式

getOffscreenBuffer

public Image getOffscreenBuffer(Component c,
                                int proposedWidth,
                                int proposedHeight)
返回屏幕外缓冲区,它应用作带有组件 c 的双缓冲区。默认情况下,每个 RepaintManager 都有一个双缓冲。该缓冲可能比 (proposedWidth,proposedHeight) 小,当最大双缓冲区的大小已设置为用于接收重绘管理器时,会发生这种情况。


getVolatileOffscreenBuffer

public Image getVolatileOffscreenBuffer(Component c,
                                        int proposedWidth,
                                        int proposedHeight)
返回可变屏幕外缓冲区,它应用作带有指定组件 c 的双缓冲区。返回的图像将是 VolatileImage 的实例,如果 VolatileImage 对象无法实例化,则为 null。此缓冲区可能小于 (proposedWidth,proposedHeight)。当最大双缓冲区的大小已设置为用于接收重绘管理器时,会发生这种情况。

从以下版本开始:
1.4
另请参见:
VolatileImage

setDoubleBufferMaximumSize

public void setDoubleBufferMaximumSize(Dimension d)
设置最大双缓冲区大小。


getDoubleBufferMaximumSize

public Dimension getDoubleBufferMaximumSize()
返回最大双缓冲区大小。

返回:
表示最大大小的 Dimension 对象

setDoubleBufferingEnabled

public void setDoubleBufferingEnabled(boolean aFlag)
在此 RepaintManager 中,启用或禁用双缓冲。小心:设置此属性的默认值可获得给定平台上的最佳绘制性能,不建议程序直接修改此属性。

参数:
aFlag - 如果激活双缓冲,则为 true
另请参见:
isDoubleBufferingEnabled()

isDoubleBufferingEnabled

public boolean isDoubleBufferingEnabled()
如果此 RepaintManager 被双缓冲,则返回 true。此属性的默认值可以随平台的改变而改变。在 AWT 中支持本机双缓冲的平台上,默认值为 false,以避免 Swing 中不必要的缓冲。在不支持本机双缓冲的平台上,默认值为 true

返回:
如果此对象被双缓冲,则返回 true

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策