Problem with Container validate() method

I have a question reqarding AWT in JDK 1.5.0_05-b05 on Windows XP.

In my very simple AWT GUI, I have a frame, which is a container of several labels and a button. The button has an action listener associated with it. The frame and its objects are initially displayed correctly. The button click and window close events behave as expected.

The problem arises in two distinctive situations:

- when this frame is deiconified from the iconified state in the tool bar,

- when the frame is moved past the screen borders and back to the screen's displayable area again.

In each situation, it looks like the frame's layout manager (GridBagLayout) adds multiple groups of their objects infinitely - the labels and the button appear over and over again, as they would have been added in a loop. It all ends in the following exception that is thrown by thevalidate() method called on the parent container.

Exception in thread"AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 512

Thevalidate() method is called after all object are added to the container (in the implementedpaint() method).

The stack trace at the time of exception is as follows:

at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:879)

at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:816)

at java.awt.GridBagLayout.ArrangeGrid(GridBagLayout.java:1412)

at java.awt.GridBagLayout.arrangeGrid(GridBagLayout.java:1372)

at java.awt.GridBagLayout.layoutContainer(GridBagLayout.java:712)

at java.awt.Container.layout(Container.java:1401)

at java.awt.Container.doLayout(Container.java:1390)

at java.awt.Container.validateTree(Container.java:1473)

at java.awt.Container.validate(Container.java:1448)

at drd.gui.AboutWindow.paint(Gui.java:639)

at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

at sun.awt.RepaintArea.paint(RepaintArea.java:224)

at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

at java.awt.Component.dispatchEventImpl(Component.java:4031)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Window.dispatchEventImpl(Window.java:1774)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Does anybody have a hint why this happens and how to solve the problem?

Thanks in advance.

Regards,

Bostjan

[2961 byte] By [Bostjan_Cargoa] at [2007-10-2 17:48:17]
# 1
> Does anybody have a hint why this happens and how to solve the problem?not without seeing how you are doing itpost (just) the gui part of your code - enough to demonstrate the problem
Michael_Dunna at 2007-7-13 19:06:17 > top of Java-index,Desktop,Core GUI APIs...
# 2

Maybe I am misinterpreting the stack trace, but...

I assume that drd.gui.AboutWindow in Gui.java belongs to you.

It looks like its paint method is calling validate.

This sounds like a really bad thing to do. Any validation had better have taken place prior to the AWT triggering any paint or repaint.

I can well believe that some really undesirable recursive behavior would result from paint calling validate.

While painting is going on, everything needs to stay put. validate causes a Container to lay out its subcomponents, so the subcomponents don't necessarily stay put.

Ian_Shefa at 2007-7-13 19:06:17 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks, Ian.I completely misinterpreted the concept of paint(). After reading your explanation, everything seems to fall in place. The program now works as expected.Best regards,Bostjan
Bostjan_Cargoa at 2007-7-13 19:06:17 > top of Java-index,Desktop,Core GUI APIs...