JDK-8068047 : JTable - JComboBox edit problem
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u25
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2014-12-20
  • Updated: 2021-01-05
  • 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.
JDK 8
8-poolResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25" (build 1.8.0_25-b18)

ADDITIONAL OS VERSION INFORMATION :
Windows 8.1 Pro

A DESCRIPTION OF THE PROBLEM :
If an editable JComboBox is used as a cell editor within a JTable, and the user makes a change then moves off the cell, using either the tab key or by clicking on another cell, the change is lost.  This is inconsistent with a normal cell where edits are not lost when the user moves to a new cell using tab or mouse clicking.
Currently, the only way to accept an edit of an editable JComboBox within a JTable is to first press enter.  Then press tab (or mouse click) to move to another cell.

This problem was reported in 1999-2001 and was supposedly fixed but it appears to have resurfaced. 

Refer to:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4275046 
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4336350



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Note: The sample code shown in bug ���4275046��� demonstrates the problem.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
---- 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 ------
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Press enter to accept the changes then press tab to move off the cell


Comments
Duplicate of JDK-8072767. JDK-8243282 is closed as duplicate of JDK-8072767 too.
05-01-2021

It's likely a duplicate of JDK-8243282.
30-10-2020

No, it does not affect 8 GA. No, it does not affect 9 (-b134).
07-09-2016

Does it affect 8 GA (b132) ?
02-09-2016

Moved to tbd_major as there are no immediate plans to address this. Marked as 7-wnf and 8-wnf as there are no immediate plans to fix for JDK 7 and 8. - Dev may decide to fix for tbd_minor/tbd_major - If there's a customer bug filed we may revisit the 7-wnf/8-wnf - will not fix - and of course the OpenJDK community may decide to address this if they require. Moved to unassigned as this will not be resolved in the near term unless there is further justification and a new requirement presented.
02-09-2016