Name: vi73552 Date: 05/25/99 I'm writing Swing-based user interface where componenents are added and removed from the interface frequently. On an occasional basis, especially when removing or adding a lot of components in a short time, I get the following exception: Exception occurred during event dispatching: java.lang.ArrayIndexOutOfBoundsException: No such child: 7 at java.awt.Container.getComponent(Container.java:148) at javax.swing.JComponent.rectangleIsObscured(JComponent.java:2816) at javax.swing.JComponent.paint(JComponent.java:546) at javax.swing.JLayeredPane.paint(JLayeredPane.java:547) at javax.swing.JComponent.paintWithBuffer(JComponent.java:3510) at javax.swing.JComponent._paintImmediately(JComponent.java:3472) at javax.swing.JComponent.paintImmediately(JComponent.java:3356) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:366) at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities. java:185) at javax.swing.SystemEventQueueUtilities.processRunnableEvent(SystemEventQueueUtilities.java :354) at javax.swing.SystemEventQueueUtilities.access$0(SystemEventQueueUtilities.java:350) at javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(SystemEventQueueUtiliti es.java:391) at java.awt.Component.dispatchEventImpl(Component.java:2376) at java.awt.Component.dispatchEvent(Component.java:2289) at java.awt.EventQueue.dispatchEvent(EventQueue.java:258) at java.awt.EventDispatchThread.run(EventDispatchThread.java:68) A quick look at the JComponent code reveals that the rectangleIsObscured method has been changed between JDK version 1.1.7 to 1.2. In version 1.2 it reads: int numChildren = getComponentCount(); for(int i = 0; i < numChildren; i++) { Component child = getComponent(i); Rectangle childBounds; IMHO this is the culprid. As this is not part of a synchronized block, the component count may change between the call to getComponentCount() and the call to getComponent. The 1.1.7 approach seems much more reliable to me: It first copies all components into an array and then loops on that array. (Review ID: 83447) ======================================================================
|