I have a JPanel which contains a lot of child components. While updating\adding new components to the parent JPanel I'd like to prevent it from repainting, how can this achieved?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try RepaintManager.currentManager(component).markCompletelyClean(component). It will prevent the component from repainting. You might need to do this after each time you add new components.
回答2:
setVisible(false)
update
setVisible(true)
回答3:
you could try by using setIgnoreRepaint(boolean value)
but it's a typical swing feature that can or cannot work (mainly because it depends from AWT so you never know).
Otherwise you could override the paint
method by using a flag that simply makes the methor return without calling super.paint()
. (actually overriding paintComponent
should be the right choice)