Skip to main content

Adding rows to a JTable causes ArrayIndexOutOfBoundsException

No replies
bmf1972
Offline
Joined: 2007-09-19

Hi all,

I am trying to hook a Swing UI for a WebService. The WebService is called in asynchronous mode, hence I need to update the UI from the WebService's handler thread. I am getting ArrayIndexOutOfBoundsException :(

At the beginning I thought that this might be a threading issue... I tried to force the UI update to happen on the event thread using the SwingUtilities.invokeAndWait() method. Same exception :(

I tried to do a dummy update by calling the UI update method from the event thread! Same exception :( Help me! I am lost!

TIA,
Adrian.

P.S. Here is the dummy UI update code:
final DefaultTableModel tableModel = (DefaultTableModel)this.resultsTable.getModel();
tableModel.insertRow(0, new Object[] {"foo", "goo"});
tableModel.insertRow(0, new Object[] {"fooooo", "gooooo"});

Also tried to add data with addRow -- same result :(

The full exception:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:
0 >= 0
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:633)
at javax.swing.JTable.getValueAt(JTable.java:2638)
at javax.swing.JTable.prepareRenderer(JTable.java:5652)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2067)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1969)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1765)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:758)
at javax.swing.JComponent.paint(JComponent.java:1022)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5104)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java
:285)
at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
at javax.swing.JComponent._paintImmediately(JComponent.java:5052)
at javax.swing.JComponent.paintImmediately(JComponent.java:4862)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQu
eueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:18
3)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:
0 >= 0
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:633)
at javax.swing.JTable.getValueAt(JTable.java:2638)
at javax.swing.JTable.prepareRenderer(JTable.java:5652)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2067)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1969)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1765)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:758)
at javax.swing.JComponent.paint(JComponent.java:1022)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java
:285)
at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
at javax.swing.JComponent.paint(JComponent.java:1008)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1797)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQu
eueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:18
3)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)