-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6
-
sparc
-
solaris_10
FULL PRODUCT VERSION :
SunOS:
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
Linux:
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
Windows:
java version "1.4.2_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_14-b05)
Java HotSpot(TM) Client VM (build 1.4.2_14-b05, mixed mode)
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
SunOS sunserver 5.8 Generic_117350-23 sun4u sparc SUNW,Sun-Fire-V210
Microsoft Windows XP [Version 5.1.2600]
Linux linuxserver 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:31:21 EDT 2003 i686 athlon i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
JTable does not cancel the cell editor when the row of a cell beeing edited is removed from the model. The row disapears (and the editor component too) but the editor is still active (table.isEditing() returns "true"!!!). When a new cell is selected, the editor tries to auto-commit the value to the cell which no longer exists. This normally leads to an IndexOutOfBoundsException.
Specifying
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
generates the IndexOutOfBoundsException immediately after the row is removed.
See bug 4777756 too!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) double click the cell of the last row to start editing
2) while the editor is still active push the "Remove Last" button which cause the model to remove the last row
3) the last row - and the cell editor too - disappear from the table
4) select another cell (NOT NEEDED if "putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)" where specified)
Note that an IndexOutOfBoundsException is thrown and the JTable do not allow editing other cells.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The editing operation must be canceled when the row of the edited cell is removed. This suppress auto-committing editor's value to an invalid cell.
ACTUAL -
The editor component remains active and tries to auto-commit the value to a cell with invalid row index. This permanently leads to IndexOutOfBoundsException which makes the JTable unusable.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.set(ArrayList.java:340)
at Test$Model.setValueAt(Test.java:83)
at javax.swing.JTable.setValueAt(JTable.java:1794)
at javax.swing.JTable.editingStopped(JTable.java:3167)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3498)
at javax.swing.JTable.editCellAt(JTable.java:2510)
at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.adjustFocusAndSelection(BasicTableUI.java:510)
at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(BasicTableUI.java:494)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
at java.awt.Component.processMouseEvent(Component.java:5097)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3195)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
public class Test extends JFrame {
public final JTable table;
public final Model model;
Test() {
super("Test");
model = new Model(10);
table = new JTable(model);
// Uncomment to generate the exception instantly
//table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
Action show =
new AbstractAction("Remove Last") {
public void actionPerformed(ActionEvent evt) {
model.removeLast();
}
};
JPanel main = new JPanel(new BorderLayout());
main.add(BorderLayout.CENTER, new JScrollPane(table));
main.add(BorderLayout.SOUTH, new JButton(show));
setContentPane(main);
setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
private static class Model extends AbstractTableModel {
private ArrayList data;
Model(int r) {
data = new ArrayList(r);
for (int i = 0; i < r; ++i) {
data.add("r_" + i);
}
}
public void removeLast() {
if (data.size() > 0) {
data.remove(data.size() - 1);
fireTableRowsDeleted(data.size(), data.size());
}
}
public int getRowCount() {
return data.size();
}
public int getColumnCount() {
return 1;
}
public String getColumnName(int col) {
return "C" + col;
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object v, int row, int col) {
data.set(row, v);
fireTableCellUpdated(row, col);
}
public Object getValueAt(int row, int col) {
return data.get(row);
}
}
public final static void main(String[] args) {
Test test = new Test();
test.pack();
test.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See workaround for bug 4777756 or:
Use only subclasses of JTable which override
public void tableChanged(TableModelEvent e)
and check for row deletion events and cancel the editor if the editing row is affected.
SunOS:
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
Linux:
java version "1.4.2_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
Windows:
java version "1.4.2_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_14-b05)
Java HotSpot(TM) Client VM (build 1.4.2_14-b05, mixed mode)
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
SunOS sunserver 5.8 Generic_117350-23 sun4u sparc SUNW,Sun-Fire-V210
Microsoft Windows XP [Version 5.1.2600]
Linux linuxserver 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:31:21 EDT 2003 i686 athlon i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
JTable does not cancel the cell editor when the row of a cell beeing edited is removed from the model. The row disapears (and the editor component too) but the editor is still active (table.isEditing() returns "true"!!!). When a new cell is selected, the editor tries to auto-commit the value to the cell which no longer exists. This normally leads to an IndexOutOfBoundsException.
Specifying
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
generates the IndexOutOfBoundsException immediately after the row is removed.
See bug 4777756 too!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) double click the cell of the last row to start editing
2) while the editor is still active push the "Remove Last" button which cause the model to remove the last row
3) the last row - and the cell editor too - disappear from the table
4) select another cell (NOT NEEDED if "putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)" where specified)
Note that an IndexOutOfBoundsException is thrown and the JTable do not allow editing other cells.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The editing operation must be canceled when the row of the edited cell is removed. This suppress auto-committing editor's value to an invalid cell.
ACTUAL -
The editor component remains active and tries to auto-commit the value to a cell with invalid row index. This permanently leads to IndexOutOfBoundsException which makes the JTable unusable.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.set(ArrayList.java:340)
at Test$Model.setValueAt(Test.java:83)
at javax.swing.JTable.setValueAt(JTable.java:1794)
at javax.swing.JTable.editingStopped(JTable.java:3167)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3498)
at javax.swing.JTable.editCellAt(JTable.java:2510)
at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.adjustFocusAndSelection(BasicTableUI.java:510)
at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(BasicTableUI.java:494)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
at java.awt.Component.processMouseEvent(Component.java:5097)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3195)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
public class Test extends JFrame {
public final JTable table;
public final Model model;
Test() {
super("Test");
model = new Model(10);
table = new JTable(model);
// Uncomment to generate the exception instantly
//table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
Action show =
new AbstractAction("Remove Last") {
public void actionPerformed(ActionEvent evt) {
model.removeLast();
}
};
JPanel main = new JPanel(new BorderLayout());
main.add(BorderLayout.CENTER, new JScrollPane(table));
main.add(BorderLayout.SOUTH, new JButton(show));
setContentPane(main);
setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
private static class Model extends AbstractTableModel {
private ArrayList data;
Model(int r) {
data = new ArrayList(r);
for (int i = 0; i < r; ++i) {
data.add("r_" + i);
}
}
public void removeLast() {
if (data.size() > 0) {
data.remove(data.size() - 1);
fireTableRowsDeleted(data.size(), data.size());
}
}
public int getRowCount() {
return data.size();
}
public int getColumnCount() {
return 1;
}
public String getColumnName(int col) {
return "C" + col;
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object v, int row, int col) {
data.set(row, v);
fireTableCellUpdated(row, col);
}
public Object getValueAt(int row, int col) {
return data.get(row);
}
}
public final static void main(String[] args) {
Test test = new Test();
test.pack();
test.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See workaround for bug 4777756 or:
Use only subclasses of JTable which override
public void tableChanged(TableModelEvent e)
and check for row deletion events and cancel the editor if the editing row is affected.
- relates to
-
JDK-4777756 JTable doesn't remove active CellEditor when TableModel changes
-
- Open
-