• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Don't repaint?

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Share some code with us so we know what you are talking about.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That worked fine, thank you
 
reply
    Bookmark Topic Watch Topic
  • New Topic