GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes How to avoid repaint? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to avoid repaint?" Watch "How to avoid repaint?" New topic
Author

How to avoid repaint?

Alex Nito
Greenhorn

Joined: Aug 17, 2009
Posts: 2
Hi,

I'm very very new to Java and I'm trying to make a simple graphics program but the thing is, everytime I resize or minimize the window, the graphics change.
I know that if I setVisible/minimize/resize the window, paint method is called and graphics are redrawn. How do I avoid that?

This is the structure of my program:


Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
You cannot. If you modify the GUI, it has to be redrawn.

Besides, why would you want to get rid of that ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Alex Nito
Greenhorn

Joined: Aug 17, 2009
Posts: 2
Sorry, I wasn't too clear. I mean, how should I modify my program to avoid the redraw?
I want to redraw only when I press the button and keep the graphics intact when I resize the window.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
the redraw happens automatically. As you resize your window, he proportions of your components change and hence have to be redrawn.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Alex Nito wrote:Sorry, I wasn't too clear. I mean, how should I modify my program to avoid the redraw?
I want to redraw only when I press the button and keep the graphics intact when I resize the window.

This makes me a little bit fearful. Are you changing a state of your program or your graphics every time it is redrawn? In other words do you have any program logic in your graphics (paint or paintComponent) method? If so, we need to talk.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to avoid repaint?