• 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

Java Forums - Image only shows after screen is reloaded (hidden and showed again)

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I have a class that calls a drawImage. The thing is that it was supposed to be shown when the JFrame is shown, but it isn't. It is only shown after I hide it and show it again (like after I minimize it and minimize it back.

Can anyone help me here? I need it loading without nothing being done by the user.

Here goes my class:

 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The general symptom you describe comes from not fully–loading the image before trying to draw it. If you are using the older "getImage" or "createImage" methods you should use a MediaTracker to load the image. The MediaTracker api has example code showing how to use it.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're doing a couple things that make me nervous:
1. Calling Component's getGraphics method -- and in a constructor, too!
That method is best avoided since it makes no persistent changes
in the component. When you repaint, that rendering will not be redone.

2. Overriding JFrame's paint method. Think art: the job of a frame is
to hold a painting, not to *be* the painting.


BTW -- I think this thread belongs in the "Swing / other things" forum.
I don't see the "other APIs" manifesting themselves...
[ November 22, 2005: Message edited by: Jeff Albrechtsen ]
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Craig, it worked perfectly.

Jeff... relax man. If you keep getting nervous like this because of other people's code you'll get old pretty soon. Anyway, thank you very much.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I've calmed down and I'm better, now. Read a few Hi and Lois strips.
But I have to admit, some code makes my head [er ... hair] stand on end!
[ November 23, 2005: Message edited by: Jeff Albrechtsen ]
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic