我正在阅读此内容:
http://www.oracle.com/technetwork/java/painting-140037.html#triggers
它提到了以下内容:
In a system-triggered painting operation, the system requests a component to render its contents, usually for one of the following reasons:
- The component is first made visible on the screen.
- The component is resized.
- The component has damage that needs to be repaired. (For example, something that previously obscured the component has moved, and a previously obscured portion of the component has become exposed).
第一点是相当明显的。然而,在确定是否需要调用 repaint() 时,第二点和第三点还有待改进。每当组件的图形属性发生变化时,我看到的几乎所有示例都会调用 repaint() 。然而,有一些迹象表明,如果我更改某些属性,我不必调用 repaint()。这些属性可能是什么?
最佳答案
当您有一个方法可以更改组件的属性,从而影响组件的绘制方式时,该方法应该调用 repaint(),而不是应用程序代码。也就是说,重画应该对程序员隐藏。
我不明白你所说的改变面板的剪辑是什么意思。剪裁是在绘画过程中完成的事情。因此,如果您有一个影响您希望完成绘制的方式的属性,则调用更改该属性的方法,该方法调用 repaint() 并且如果剪切区域已更改,则您的绘制例程将使用该信息,而正在画画。
关于java - 什么会触发 AWT 中组件对 Paint() 的隐式调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331962/