JTable - removing row

Hello.

I am using a JTable that needs to have rows added and removed.

To remove the last row of the table I use the line:

Def_model.removeRow( table.getModel().getRowCount() - 1 );

Def_model is a DefaultTableModel and table is a JTable

After I removed the line I could do select another cell (with the mouse) the folowing exception was trown:

Exception in thread"AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 21 >= 21

at java.util.Vector.elementAt(Vector.java:427)

at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:648)

at javax.swing.JTable.setValueAt(JTable.java:2676)

at javax.swing.JTable.editingStopped(JTable.java:4675)

at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:125)

at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:330)

at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:215)

at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:5419)

at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:986)

at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)

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

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:3983)

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 did not understood what was hapenning. Ther is no reference to the class I was creating in the exception. What was I doing wrong?

Well, i had a KeyListener added to the DefaultCellEditor's Component. In the KeyListener i had a System.out.println( "MyClass etc... that was sending output every time a key was pressd, even after the line i was editing was removed. I changed My code for:

editor.stopCellEditing();

Def_model.removeRow( table.getModel().getRowCount() - 1 );

editor is a DefaultCellEditor object.

With this code every thig works fine.

It seem to me that JTabledo not stop editing a cell even if the line it was in was REMOVED.

Is this the expected behavior? I did not find any reference on this in the documentation.

This situation is very hard to debug because the exception is not trown from programers class.

Is this a swing bug?

[3639 byte] By [luisfrpereiraa] at [2007-11-26 17:39:01]
# 1
pretty old bug. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4777756There is a workaround at the end of the bug report
Jasprea at 2007-7-9 0:07:11 > top of Java-index,Desktop,Core GUI APIs...
# 2
> It seem to me that JTable do not stop editing a cell even if the line it was in was REMOVED.table = new JTable(...);table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
camickra at 2007-7-9 0:07:11 > top of Java-index,Desktop,Core GUI APIs...
# 3

> > It seem to me that JTable do not stop editing a

> cell even if the line it was in was REMOVED.

>

> table = new JTable(...);

> table.putClientProperty("terminateEditOnFocusLost",

> Boolean.TRUE);

Where can I get the list of all the property keys and possible key objects?

Where is this documented ?

Thank you.

luisfrpereiraa at 2007-7-9 0:07:11 > top of Java-index,Desktop,Core GUI APIs...
# 4
> Where is this documented ?Its not. You can search the web or search the Java source code.
camickra at 2007-7-9 0:07:11 > top of Java-index,Desktop,Core GUI APIs...
# 5
Thank you for the tip.I found a list of about 70 property keys.
luisfrpereiraa at 2007-7-9 0:07:11 > top of Java-index,Desktop,Core GUI APIs...