File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Leticia Barbalho
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • 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:

 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic