views:

127

answers:

3

Hi,

My application does not paint itself on startup. When resizing it or minimizing/maximizing it, the window of the application is painted.

This problem only appears on Windows machines (I tested XP, Vista and Windows 7). On Mac OS X and Linux, the application works fine.

The machines have installed java 6. My application uses the AWT, so not Swing. I tried using Swing (so JFrame in stead of Frame), but this does not solve the problem.

I checked the calls on repaint(), update() and paint() of the frame. They all appear, and the image to draw is available. I also checked if these calls are done on the EDT thread. This is the case. When the window is resized (or min/max-ed) a call on paint() is done by the system, and the image is drawn.

My fear is that I'm missing something really obvious. I'm making the frame visible, validate it (also tested with invalidate) and repaint it. This is sufficient in Mac OS X and Linux.

Does somebody have any suggestions to what I should do, or what else to try?

Thanx in advance

Maurice

A: 

My guess is that you are overriding Frame.paint. You will probably get better results from painting to a JPanel (or Canvas, if you insist on the obsolete AWT), and when you do that, make sure you're overriding JPanel's paintComponent, rather than paint. In some cases, a JLabel with an ImageIcon can be simpler still.

As others have suggested, though, try to post a test case.

Ricky Clarkson
A: 

It is difficult to diagnose the problem without seeing any source code, but is the image fully loaded?

AWT loads images in the background after, so even though a call to Toolkit.getImage() may return a valid Image instance, this does not mean that the image is loaded by that time. You can use a MediaTracker to track this.

Grodriguez
+1  A: 

You might want to check out this debugging trick using a custom RepaintManager. It helped me track down some tricky intermittent swing glitches.

http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html

bemace