aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help! Why isn't my Window paint method called? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help! Why isn Watch "Help! Why isn New topic
Author

Help! Why isn't my Window paint method called?

Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
I have a splash window which is just a java.awt.Window with an image painted on it. I create the image via ImageIcon (and it does get loaded), and set the window size based on this. Then in paint() I have:



But all it shows is a gray square! It never prints the line "painting" What's going on?

EDIT: Weird thing. When I change my setVisible method to the below code, it shows the image! This shouldn't be required to get the paint method to be called (even though the window whos up, gray, paint is never called)! What's going on?


[ October 09, 2006: Message edited by: Dan Bizman ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if paint(), with the drawimage, belongs to the ImageIcon, perhaps you are setting the window's visibility to true before adding the ImageIcon.

it would be better for you to post the exact code, so we can see how you
are putting it all together.
Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
Originally posted by Michael Dunn:
if paint(), with the drawimage, belongs to the ImageIcon, perhaps you are setting the window's visibility to true before adding the ImageIcon.

it would be better for you to post the exact code, so we can see how you
are putting it all together.


I'm not. This is all my code has:

1. In constructor, it makes the imageIcon, saves the image via imageIcon.getImage(), saves the width/height of image (as imageWidth/imageHeight), sets the size to those and sets location.

2. See above for "paint" method

That's it. And here's the weird thing:

If I run an application with nothing but my splash window in it, it shows up properly, BUT, if I run it during my application (when other stuff is happening in the background on other threads), it shows as a gray box and never calls paint.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
only other thing I can think of is one of your 'other stuff' threads is
running on the EDT
Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
Originally posted by Michael Dunn:
only other thing I can think of is one of your 'other stuff' threads is
running on the EDT


How do I find that out? And assuming that is the case, what do i do?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's an example of one way to test

 
Don't get me started about those stupid light bulbs.
 
subject: Help! Why isn't my Window paint method called?
 
Similar Threads
Layout
Canvas not displaying
Component on Image
How to avoid repaint?
Resize JFrame to fit image