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.
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.
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 ]
There is no emoticon for what I am feeling!
Joined: Sep 02, 2005
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.
Joined: Sep 16, 2005
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 ]