JDK-4778542 : property "terminateEditOnFocusLost" results in distorted cell when editing table
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1,5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_98,windows_xp
  • CPU: x86
  • Submitted: 2002-11-14
  • Updated: 2005-01-15
  • Resolved: 2005-01-15
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 6
6 b20Fixed
Related Reports
Duplicate :  
Relates :  
Description

Name: jk109818			Date: 11/13/2002


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)


FULL OPERATING SYSTEM VERSION :

Windows 98 [Version 4.10.2222]

A DESCRIPTION OF THE PROBLEM :
The cell does not edit properly.  The display screw up and
partially hightlight of text was shown (couple characters
were highlighted, the rest is not).  Many times, users have
to click twice for it to work. Very inconsistently.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Run the attached code
2.Click on clickme twice (once may do)
3.Click on the 2nd col(methode) and row 3
4. Click on the 2nd col (methode) and row 2
5. Click on the 2nd col (methode) and row 2 (again)
6. Click on the 2nd col (methode) and row1
7. Click on any row of 2nd column once or twice

EXPECTED VERSUS ACTUAL BEHAVIOR :
When click 1 time, the cell will be editable, and the cursor
will be either:
1) befire first character
2) at the click point
3) at the last chacter
4) the cell must be edited

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;

public class ComboEditorTest extends JFrame {
	
	// fill in table values
	public static String[]	colNames = {
		"no.", "methode", "id 1", "id2", "sample weight", "unit"
	};
	public static Object[][]		data = {
		{
			new Integer(1), "chlorid", "123456789012345678901234",
				"4711 - 0815", new Float(7.2348), "g"
		}, {
			new Integer(2), "chlorid", "123456789012345678901234",
				"4711 - 0815", new Float(7.2348), "g"
			}, {
				new Integer(3), "chlorid", "123456789012345678901234",
					"4711 - 0815", new Float(7.2348), "g"
			}
	};
	
	public ComboEditorTest() {
		JTable table = new JTable(data, colNames);
		
		JScrollPane scrollPane = new JScrollPane(table);
		scrollPane.setPreferredSize(new Dimension(450, 100));
		getContentPane().add(scrollPane);
		JButton btntest = new JButton("Click me");
		getContentPane().add(btntest, BorderLayout.SOUTH);
		
		// use a combo box as cell renderer for the 2nd column
		JComboBox cb = new JComboBox();
		cb.setEditable(true);
		cb.addItem("chlorid");
		cb.addItem("HCl");
		cb.addItem("water");
		cb.addItem("NaCl");
		cb.addItem("crystall water");
		cb.addItem("anything");
		TableColumn col = table.getColumnModel().getColumn(1);
		col.setCellEditor(new DefaultCellEditor(cb));
		table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
		
		addWindowListener(new WindowAdapter()  {
			public void windowClosing(WindowEvent evt)	{
				System.exit(0);
			}
		});
	}
	
	public static void main(String[] args)	{
		ComboEditorTest test = new ComboEditorTest();
		test.pack();
		test.setVisible(true);
	}
	
}

---------- END SOURCE ----------
(Review ID: 164745) 
======================================================================

Comments
EVALUATION Yes, I definitely see this bug. Commit to tiger. ###@###.### 2002-11-14 The problem is simply that JTable doesn't tell the editor to repaint after adding it to the component hierarchy. This is not an issue if the table repaints the area, but this doesn't happen in this case since there is no selection change and focus is going right to the editor. ###@###.### 2004-12-20 20:20:55 GMT Was asked for a more thorough evaluation by Kleopatra in the forums. So here goes: First, let's recap the problem: It's all about weird painting behavior when using the property "terminateEditOnFocusLost". In essence, the steps in the bug describe a case where you click in a cell and the editor appears without painting properly. The root cause of this is that JTable does not tell the editor to repaint itself when it is added to the component hierarchy. As you know, a repaint is needed to display newly added components. Now, in many cases this isn't a problem. Typically, clicking on a cell also causes selection to change to that cell - in which case JTable does a repaint of that area anyway. So the problem only manifests when clicking on a cell that is already selected. The fix was to add "editorComp.repaint()" towards the end of JTable.editCellAt(), right after the call to "editorComp.validate()". Now, there is still another problem to be addressed, and you've probably seen this. This is the fact that when you click on one cell with an editor and then click on a second cell with an editor, the editor appears and then immediately dissapears. This occurs due to an AWT policy of auto transferring focus when a component is removed from the hierarchy. I've filed bug 6210779 and both Swing and AWT are already looking into it. ###@###.### 2004-12-22 18:42:08 GMT
22-12-2004

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon mustang
25-09-2004