Java window paint issue

My application does not draw itself at startup. When resizing or minimizing / maximizing the application window 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 installed java 6. My application uses AWT, not Swing. I tried using Swing (so JFrame instead of Frame), but this does not solve the problem.

I checked the calls to repaint (), update () and paint () of the frame. They all appear, and a drawing image is available. I also checked if these calls were made in the EDT thread. In this case. When the window (or min / max-ed) is resized, the paint () call is made by the system and the image is drawn.

My fear is that I'm missing something really obvious. I make the frame visible, check it (also checked with a sign of invalidity) and redraw it. This is enough for Mac OS X and Linux.

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

Thanx in advance

Maurice

+4
source share
3 answers

I assume you are overriding Frame.paint. You will probably get better results from painting to JPanel (or Canvas if you insist on legacy AWTs), and when you do, make sure you override JPanel paintComponent, not paint. In some cases, JLabel with ImageIcon may be even easier.

As others suggested, try posting a test case.

+1
source

You might want to test this debugging trick with a custom RepaintManager. It helped me track down some dodgy erratic swings.

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

+1
source

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 although calling Toolkit.getImage() may return a valid Image instance, this does not mean that the image is loading by now. You can use MediaTracker to track this.

0
source

All Articles