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?
Asked
Active
Viewed 1.1k times
2
-
1I've never noticed significant latency. Can you provide an sscce http://sscce.org/ that demonstrates the problem? – trashgod Oct 31 '10 at 22:31
-
I agree with trashgod, I've never seen this problem. Components are not painted as they are added to a panel because by default they have a 0 size so there is nothing to paint. The components will only be painted after you invoke panel.revalidate() because this invokes the layout manager which in turn lays out the components and gives them a size. If you are doing something strange, then we need a SSCCE to understand what you are doing. – camickr Nov 01 '10 at 04:33
3 Answers
8
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.

Denis Tulskiy
- 19,012
- 6
- 50
- 68
1
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)

Jack
- 131,802
- 30
- 241
- 343
-
2`setIgnoreRepaint(boolean value)` is for something completely different. The Java Doc says: `Sets whether or not paint messages received from the operating system should be ignored. This does not affect paint events generated in software by the AWT, unless they are an immediate response to an OS-level paint message. This is useful, for example, if running under full-screen mode and better performance is desired, or if page-flipping is used as the buffer strategy.` – Frederic Leitenberger May 21 '14 at 14:17