JDK-6788481 : CellEditorListener.editingCanceled is never called
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-12-23
  • Updated: 2022-12-05
  • Resolved: 2022-11-29
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.
JDK 20
20 b26Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When editing of a table cell is canceled the funcion editingCanceled of the registered listener CellEditorListener is not called, but it should be called according to the docs. (Note: The function editingStopped of the same listener is called correctly)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Start cell editing then press Esc.  "canceled" should be printed on console, but there is no such text (CellEditorListener.editingCanceled is never called). (If you stop editing by pressing Enter  for example then "stopped" is printed on console correctly)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"canceled" should be printed on console after canceling cell editing.
ACTUAL -
no text is printed on console.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
 
public class BugCellEditorListener extends JFrame
{
	BugCellEditorListener()
	{
		JTable table = new JTable(5,5);
		table.setPreferredScrollableViewportSize(table.getPreferredSize());
		JScrollPane scrollpane = new JScrollPane(table);
		getContentPane().add(scrollpane);
 
		DefaultCellEditor dce = (DefaultCellEditor)table.getDefaultEditor(Object.class);
		dce.addCellEditorListener( new CellEditorListener()
		{
			public void editingStopped(ChangeEvent e)
			{
				System.out.println("stopped");
			}
 
			public void editingCanceled(ChangeEvent e)
			{
				System.out.println("canceled");
			}
		});
	}
 
	public static void main(String [] args)
	{
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new BugCellEditorListener();
				frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
				frame.pack();
				frame.setLocationRelativeTo( null );
				frame.setVisible(true);
			}
		});
	}
}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Partial w/a: catch "Esc" with InputMap/ActionMap and call CellEditor.cancelCellEditing. But cell editing is canceled also when the table is resized, so to catch this cancelation the events of resizing should be catched also. (I don't know exactly maybe there are some other ways to cancel cell editing).

Comments
Changeset: 4e8e853b Author: Prasanta Sadhukhan <psadhukhan@openjdk.org> Date: 2022-11-29 05:08:38 +0000 URL: https://git.openjdk.org/jdk/commit/4e8e853bc9b9ac3a89a9e25b9fec5381b8255806
29-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10964 Date: 2022-11-03 07:05:10 +0000
03-11-2022

EVALUATION The bug is reproducible
25-12-2008