JDK-4503845 : Cell editing does not complete when JTable loses focus
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1,1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,solaris_2.6,solaris_8,windows_95,windows_98,windows_nt generic,solaris_2.6,solaris_8,windows_95,windows_98,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2001-09-17
  • Updated: 2002-06-13
  • Resolved: 2002-03-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
1.4.1 hopperFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  

Name: gm110360			Date: 09/17/2001

java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)

  To reproduce the problem, run the attached program, enter data into a cell, and
then click on another UI component.  The data that was entered is now gone.
This happens consistently the first time data is entered into a cell and the
table loses focus before the edit operation is completed.

Repeat the operation, double-click on a cell, enter some data, and then click
on another UI component.  This time, the data remains, but the CellEditor
remains active and the edit operation is not completed.  If you select the
Print Function, it is apparent that the entered data was never saved.

The second aspect of the problem was reported against 1.2.2 & 1.4 beta.  It
also exists in 1.3.  Bugs 4460382 is closed and the problem is reported fixed
in merlin - Beta 2.  Well, apparently not.  In fact, the problem with the
CellEditor has another aspect to it right now.

I have not been able to get any of the supposed workarounds to work.  There
have been comments that this would get fixed in 1.4 - my fear is that since it
has been closed (I believe in error), the problem will slip through the cracks.


import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class FrameNTable extends JFrame {
  JTable table, table2, table3;
  String[] columnNames = {"String", "String", "String"};
  Object[][] data = { {null, null, null},
                      {null, null, null},
                      {null, null, null} };
  public FrameNTable() {
	String version = System.getProperty("java.specification.version");
    	System.out.println("Java specification version = " + version );
  private void createGUI() {
	JPanel contentPane = new JPanel();
   	contentPane.setLayout(new BorderLayout());
    	// create the JTable
    	TableModel tableModel = new MyTableModel();
	table = new JTable(tableModel);
	contentPane.add(table, BorderLayout.CENTER);

	// add some other components for variety
        JPanel panel = new JPanel();
        JTextField textField1 = new JTextField("Field 1");
        JTextField textField2 = new JTextField("Field 2");
	JButton button = new JButton("Print");
        contentPane.add(panel, BorderLayout.SOUTH);

        button.addActionListener(new java.awt.event.ActionListener() {
        	public void actionPerformed(ActionEvent e) {
                	for (int i = 0; i < 3; i++) {
        			for (int j = 0; j < 3; j++) {
        				System.out.print(data[i][j] + "  ");
  class MyTableModel extends AbstractTableModel {

    public MyTableModel () {
    public int getColumnCount() {
      	return columnNames.length;
    public int getRowCount() {
      	return data.length;
    public String getColumnName(int col) {
      	return columnNames[col];
    public Object getValueAt(int row, int col) {
     	return data[row][col];
    public void setValueAt(Object value, int row, int col) {
      	data[row][col] = value;
    public Class getColumnClass(int col) {
      	return java.lang.String.class;
    public boolean isCellEditable(int row, int col) {
        return true;
  public static void main (String[] args) {
    FrameNTable frame = new FrameNTable();
(Review ID: 132040) 

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper FIXED IN: hopper INTEGRATED IN: hopper VERIFIED IN: hopper-beta

WORK AROUND Name: gm110360 Date: 09/17/2001 The reported workarounds do not work for me. ======================================================================

EVALUATION The first issue in the description deals with the improper behavior of losing edits on focus exit the first time but for not subsequent attempts. The problem was correctly diagnosed by Kleopatra in bug report 4518907. java.swing.JTable indeed does need to set 'editorRemover' to null after calls to removePropertyChangeListener("focusOwner", editorRemover); in both removeNotify() and in removeEditor(). That change makes the behavior consistent - now edits are lost every time focus is lost without an edit commit, which is the subject of the second issue, and will be tracked with bug 4709394. ###@###.### 2001-10-26