JDK-8058525 : Editable ComboBox in JTable does not get edited text as selected item
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2014-09-15
  • Updated: 2020-11-12
  • Resolved: 2020-11-12
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.
Other
tbdResolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

A DESCRIPTION OF THE PROBLEM :
A JTable uses an editable JComboBox as editor. When typing text in the combo box and stopping the editor by clicking in another editable cell of the JTable, the text is not committed.

May be JDK-8032878 is a hint?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code appended as executable test case.
Click into the cell "Key 2", select the text and type "Foo" in there.
Click into the cell "Value 2".

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"Foo" should be the value of the cell in (0, 1).
ACTUAL -
The value of cell (0, 1) is "Key 2".

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class EditableComboBoxInJTable
{
	public static void main(String[] args)
	{
		JFrame frame = new JFrame();
		frame.setSize(300, 200);
		frame.setLocationRelativeTo(null);
		frame.setLayout(new FlowLayout());
		frame.add(_createTable());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	private static JTable _createTable()
	{
		JTable            table;
		JComboBox<?>      comboBox;
		DefaultCellEditor comboEditor;
		JTextField        textField;
		DefaultCellEditor textEditor;

		table = new JTable(new String[][]{
			{"Key 1", "Value 1"}, {"Key 2", "Value 2"},
			{"Key 3", "Value 3"}, {"Key 4", "Value 4"}},
			new String[]{"Keys", "Values"});

		comboBox = new JComboBox<String>(new String[]{"Key 1", "Key 2", "Key 3", "Key 4"});
		comboBox.setEditable(true);

		comboEditor = new DefaultCellEditor(comboBox);
		comboEditor.setClickCountToStart(1);

		textField  = new JTextField();

		textEditor = new DefaultCellEditor(textField);
		textEditor.setClickCountToStart(1);

		table.getColumnModel().getColumn(0).setCellEditor(comboEditor);
		table.getColumnModel().getColumn(1).setCellEditor(textEditor);

		return table;
	}
}
---------- END SOURCE ----------


Comments
Looks as the duplicate of JDK-8243282.
30-10-2020