我想在 a 上画一条垂直线JPanel
,并让它滑过它,而不需要这个过程调用paintComponent()
. JPanel
我曾考虑过使用,GlassPane
但我认为这不是正确的方法,因为框架中还有其他组件包含JPanel
,因此它不是特定于它(而且我实际上不确定它不会调用paintComponent()
反正)。
有任何想法吗?
我想在 a 上画一条垂直线JPanel
,并让它滑过它,而不需要这个过程调用paintComponent()
. JPanel
我曾考虑过使用,GlassPane
但我认为这不是正确的方法,因为框架中还有其他组件包含JPanel
,因此它不是特定于它(而且我实际上不确定它不会调用paintComponent()
反正)。
有任何想法吗?
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.
即使使用 GlassPane,也必须在某些时候重新绘制底层组件。没有避免paintComponent
调用 JPanel 的好方法。
但是,JPanel 不应该做paintComponent
除绘画以外的事情。如果您试图避免调用它,那么听起来您的paintComponent
方法中有一些东西需要以某种方式更改或缓存。
您是否有不想在 JPanel 上调用 paintComponent() 方法的原因?重新绘制对象以呈现在其上滑动的线条很可能是最简单的解决方案。