3

我想在 a 上画一条垂直线JPanel,并让它滑过它,而不需要这个过程调用paintComponent(). JPanel我曾考虑过使用,GlassPane但我认为这不是正确的方法,因为框架中还有其他组件包含JPanel,因此它不是特定于它(而且我实际上不确定它不会调用paintComponent()反正)。

有任何想法吗?

4

3 回答 3

2

Maybe you should be using Layered Panes if you just want to isolate the line painting code from the rest of your painting code.

If your painting code is expensive, then maybe you should be creating a BufferedImage and then just redraw the image in your paintComponent() code. This is faster than repainting from scratch every time.

于 2011-05-18T16:12:59.097 回答
2

即使使用 GlassPane,也必须在某些时候重新绘制底层组件。没有避免paintComponent调用 JPanel 的好方法。

但是,JPanel 不应该做paintComponent除绘画以外的事情。如果您试图避免调用它,那么听起来您的paintComponent方法中有一些东西需要以某种方式更改或缓存。

于 2011-05-18T16:02:23.687 回答
0

您是否有不想在 JPanel 上调用 paintComponent() 方法的原因?重新绘制对象以呈现在其上滑动的线条很可能是最简单的解决方案。

于 2011-05-18T19:37:34.653 回答