Problems with Painting Window Twice
I am trying to debug a mature (read:has been around for a while) Swing application which has the following problem:
Whenever the application opens a new window (JFrame), if it is going to open it maximized, it will do a pack, set to maximized state, and a setVisible(true).
However, when displayed on screen, I notice it first paints the contents of the window at the "packed size" then a split second later paints it maximized. This is more noticable on slower machines as well.
To help debug the problem, I created a sample window (JFrame) that contains a JTable and three buttons (i.e. no "legacy code").
I do the following:
int state = getExtendedState();
state |= Frame.MAXIMIZED_BOTH;
And the same problem occurs.
I also tried to show the window early on in the startup sequence of the application and there is no issue. The issue only occurs towards the end of the startup sequence but I cannot pinpoint the exact time (my guess is something's occurring on another thread?).
I also overrode the paint() method on the test JFrame and put a breakpoint there.
Early on when it paints correctly, the paint method is called once. Afterwards, it is always called twice.
When I was testing it today both paint method calls were the result of an InvocationEvent.
Each InvocationEvent has a Runnable an in this case they were SystemEventQueueUtilities.ComponentWorkRequest objects. I noticed that in one of the paint calls, the object had the same id (i.e. it was the same object).
So, my question is the following:
What could be causing this?
And what are some strategies in uncovering the cause of this?
For the record, I am testing this under Windows XP, Java 1.6 Update 11. It has had this issue for all versions of 1.6. I'm using the Windows look and feel and I also tested it under the Nimbus look and feel. Same issue.
In addition, if a window is not displayed initally in its maximized state but in its "packed size", I notice it first paints the window border and then paints the contents. I feel it is the same issue.
In addition, previous versions of Java had this issue but the background within the window border was opaque before it painted the contents. It had this issue in 1.5, 1.4, and, if I can even remember correctly, 1.3.