aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Don't repaint? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Don Watch "Don New topic
Author

Don't repaint?

Carl Pettersson
Ranch Hand

Joined: Sep 09, 2003
Posts: 73
I've got a JFrame that draws an image, but as soon as the image is drawn, the window repaints. How do I force the image to remain drawn? The image is drawn in a method, and as soon as that method exits, the frame is emptied.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8873
    
    8

Share some code with us so we know what you are talking about.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Put the image drawing code in the paint() or paintComponent() method. If you're painting to the component anywhere else it won't be a lasting change (as you've found).


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Carl Pettersson
Ranch Hand

Joined: Sep 09, 2003
Posts: 73
How do I override the paint method for only one JFrame? I might have forgotten to mention it in my first post, I've got two JFrames which will be visible at the same time, if I override paint, won't it paint the image over both frames?
As for code, I don't know if there is anything spectacular about it that will highlight my problem. What I do is create the image, then draw it on the JFrame jf_work using jf_work.drawImage(bi, 0, 0, this);
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8873
    
    8

Originally posted by Carl Pettersson:
How do I override the paint method for only one JFrame?

Subclass JFrame and use that to create one of your frames. Use a regular JFrame to create the other.


As for code, I don't know if there is anything spectacular about it that will highlight my problem.

Guess I could use my Magic 8 Ball. . .
The answer is VERY DOUBTFUL
Make of it what you will.
Carl Pettersson
Ranch Hand

Joined: Sep 09, 2003
Posts: 73
That worked fine, thank you
 
Don't get me started about those stupid light bulbs.
 
subject: Don't repaint?