Prevent Java from repainting the content of a JPanel while updating

我只是一个虾纸丫 提交于 2020-01-09 11:58:08

问题


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)



来源:https://stackoverflow.com/questions/4065456/prevent-java-from-repainting-the-content-of-a-jpanel-while-updating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!