Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to avoid repaint?

 
Alex Nito
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot. If you modify the GUI, it has to be redrawn.

Besides, why would you want to get rid of that ?
 
Alex Nito
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the redraw happens automatically. As you resize your window, he proportions of your components change and hence have to be redrawn.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic