在Swing中清楚绘图面板的前景 [英] Clear foreground of a drawing panel in Swing
问题描述
制作这个画笔程序我决定要清除面板容器( panel2
在链接代码中)。我使用了 PanelName.setForeground(null)
,它工作。我想知道的是,是否存在此方法的已知缺陷以及从容器中移除图形对象的其他方式。
<如果你重载 paintComponent
,你可以使用 Graphics 。 oracle.com/javase/7/docs/api/java/awt/Graphics.html#clearRect%28int,%20int,%20int,%20int%29\">Graphics#clearRect$c$ C>
。但总的来说,我更喜欢你的方法,因为我会要求你继承 JPanel
,或者匿名声明一个。
Making this paintbrush program I decided I want to clear the panel container (panel2
in the linked code). I used PanelName.setForeground(null)
and it worked. What I'd like to know is if there are known drawbacks of this approach and other ways of removing graphics objects from the container.
If you override paintComponent
, you can clear its Graphics
using Graphics#clearRect
. But overall, I prefer your approach because mine would require you to either subclass JPanel
, or anonymously declare one.
这篇关于在Swing中清楚绘图面板的前景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!