JTable addColumn() produces ArrayIndexOutOfBoundsException

Hi everyone!

I have a JTable in which I added a new column using:

TableColumn tc=new TableColumn();

dtm.addColumn("headerTitle",DataVector);

where dtm is de TableModel of this JTable.

It works fine adding the column, but when I click the column cells the application returns the following exception:

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

at editorhorarios.janelaPrincipal$14.isCellEditable(janelaPrincipal.java:625)

at javax.swing.JTable.isCellEditable(JTable.java:2686)

at javax.swing.JTable.editCellAt(JTable.java:3423)

at javax.swing.plaf.basic.BasicTableUI$Handler.mouseReleasedDND(BasicTableUI.java:1160)

at javax.swing.plaf.basic.BasicTableUI$Handler.mouseReleased(BasicTableUI.java:1130)

at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)

at java.awt.Component.processMouseEvent(Component.java:6038)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)

at java.awt.Component.processEvent(Component.java:5803)

at java.awt.Container.processEvent(Container.java:2058)

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

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

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

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)

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

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

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

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

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)

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)

I can磘 understand this exception. I need help to resolve this problem!

Thanks in advance!;)

[2508 byte] By [GrEga] at [2007-11-27 4:37:38]
# 1
> at editorhorarios.janelaPrincipal$14.isCellEditable(janelaPrincipal.java:625)The stack trace tells you the line number of the statement that is causing the problem.
camickra at 2007-7-12 9:47:56 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks for your help camickr.

Well, I know the location of the possible problem, but i can磘 resolve it.

I think that, because I have created this column with the addColumn method, the DataVector of this JTable model doesn't contain the new column. Note that i created a column Datavector.

So when I try to edit the created cells the method JTable.isCellEditable returns an error trying to look in positions that the DataVector doesn't contains.

Please, new help will be regarded..

Thanks in advance.

GrEga at 2007-7-12 9:47:56 > top of Java-index,Desktop,Core GUI APIs...
# 3

> I think that, because I have created this column with the addColumn

> method, the DataVector of this JTable model doesn't contain the new

> column. Note that i created a column Datavector.

First of all use proper Java naming conventions. Don't upper case the first word of a variable name. Only classes should have the first word upper cased. Your "DataVector" looks like a class name not a variable name.

Secondly, the Vector should contain data for the new column, so the size of the Vector would be equal to the number of rows currently in the table and each element should have a non null value.

camickra at 2007-7-12 9:47:56 > top of Java-index,Desktop,Core GUI APIs...
# 4
I think your DataVector should be already created and filled when you add it.BTW, your TableColumn creation has no effect on the code fragment you posted; you might want to to something else instead.
sztyopeka at 2007-7-12 9:47:56 > top of Java-index,Desktop,Core GUI APIs...