JDK-4275046 : JTable does not handle editable JComboBox as cell editor correctly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_7,windows_98
  • CPU: x86,sparc
  • Submitted: 1999-09-23
  • Updated: 2014-12-22
  • Resolved: 2001-07-25
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
1.4.0 beta2Fixed
Related Reports
Duplicate :  
Relates :  
Description
ing the default cell editor in a JTable, if I click to edit a cell,
type in some characters, and then click in another cell, the newly
entered text is made part of the field.

If I use an editable JComboBox as a cell editor, click in the cell to
edit it, type some characters into the text field in the JComboBox, and
then click in another cell, the text entered into the JComboBox is not
made part of the field.  Instead, you have to hit Enter after entering
the text, before clicking in another field.  Of course, hitting Enter in
a regular text field moves you to the next row.

This inconsistency makes it difficult to use a JComboBox as a cell editor
with a set of canned values that are easy to enter into a field.

================
More description from a duplicate bug:

A JComboBox using the DefaultCellEditor (in a JTable) shows the following
problems:

1. Pressing ESC while the drop down list is displayed removes the list
   but does not cancel the JTextField editor.

2. If you modify the value in the text field, the only way to accept
   the change is to press return. If you click on another cell in the table
   the change is lost. 

Reproduced with Java 1.3.0-C on Solaris using TableExample4 in the Swing 1.1
examples (change the combobox to be editable).

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin merlin-beta2 FIXED IN: merlin-beta2 INTEGRATED IN: merlin-beta2
14-06-2004

PUBLIC COMMENTS .
10-06-2004

SUGGESTED FIX Name: pzR10082 Date: 07/05/2001 *** /tmp/geta3948 Tue Jul 3 10:47:24 2001 --- DefaultCellEditor.java Tue Jul 3 10:47:24 2001 *************** *** 132,137 **** --- 132,143 ---- } return true; } + + public boolean stopCellEditing() { + comboBox.actionPerformed(new ActionEvent( + DefaultCellEditor.this, 0, "")); + return super.stopCellEditing(); + } }; comboBox.addActionListener(delegate); } ###@###.### 2001-07-03 ======================================================================
03-07-2001

EVALUATION It may be possible to change the implementation of the ConboBox constructor in the DefaultCellEditor so that it issues the appropriate notification to the ComboBox on receiveing the editingStopped() message. Handing this over to the ComboBox owner for further assessment ... philip.milne@eng 2000-01-03 -------------- Verified this inconsistency in 1.3 FCS. Will try to resolve for the next major release. Here is a test case to reproduce the inconsistency. The basic problem is that when the focus is transferred out of the ComboBox editor, the previous value is restored. If a tab or the enter key is pressed in the ComboBox editor, the edited value is accepted. The solution is to have a focus listener atached to the editor to detect focus changes and accept the edited contents. ---- ComboEditorTest.java ------ 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); // 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)); 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 ComboEditorTest.java ------ mark.davidson@Eng 2000-05-01 Hmmmm... The tabbing out of the Combo box cell editor no longer works as of b35. This indicates that it could have been due to a focus regression. One problem which still exists is that the heavyweight popup doesn't accept the enter key. mark.davidson@Eng 2001-06-27
27-06-2001

WORK AROUND Tab out of the edited field or use the enter key to accept the edited value of the combo box editor. mark.davidson@Eng 2000-05-01
01-05-2000