JDK-8072767 : DefaultCellEditor for comboBox creates ActionEvent with wrong source object
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-07
  • Updated: 2015-12-07
  • Resolved: 2015-04-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 9
9 b65Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Recent implementation of JComboBox.actionPerformed(ActionEvent e) in Java 1.8 checks that the given ActionEvent source is identical with  ComboBoxEditor editor returned by getEditor().

In the same Java version EditorDelegate implementation used in DefaultCellEditor(final JComboBox comboBox) generates ActionEvent using DefaultCellEditor.this as its source in its method stopCellEditing()

comboBox.actionPerformed(new ActionEvent(
                                     DefaultCellEditor.this, 0, ""));

ComboBoxEditor and DefaultCellEditor are different things.

Therefore this call is ignored by JComboBox  in the recent Java version. Implementation of stopCellEditing in this EditorDelegate  should be fixed.

REGRESSION.  Last worked in version 7u75

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following application.

Click at cell "Kathy" , replace its content by text "Andrew". Do not hit "Enter".

Then click at cell "Smith" and replace its content by text "Brown" .  Do not hit "Enter".

Then click at cell "John", and replace its content by text "Robert" . Press TAB.


// CODE BEGIN
/*
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
 * Modified by Dimitry Polivaev, 2015
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Oracle or the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */ 

package components;

/*
 * SimpleTableDemo.java requires no other files.
 */

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class SimpleTableDemo extends JPanel {

    public SimpleTableDemo() {
        super(new GridLayout(1,0));

        String[] columnNames = {"First Name",
                                "Last Name"};

        Object[][] data = {
	    {"Kathy", "Smith"},
	    {"John", "Doe"}};

        final JTable table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);
        
        final JComboBox<Object> comboBox = new JComboBox<>();
        comboBox.setEditable(true);
		table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));
        table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JTextField()));
        
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this panel.
        add(scrollPane);
    }


    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("SimpleTableDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        SimpleTableDemo newContentPane = new SimpleTableDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

// CODE END


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The first table row should contain cells with content "Andrew" and "Brown".
The second line should contain cells with content "Robert" and "Doe".
ACTUAL -
The first table row contains cells with content "Smith" and "Brown".
The second line should contain cells with content "John" and "Doe

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Use following combobox implementation:

final JComboBox<Object> comboBox =  new JComboBox(){
@Override
public void actionPerformed(ActionEvent e) {
  if(e != null && e.getSource() == table.getCellEditor())
    super.actionPerformed(new ActionEvent(getEditor(), e.getID(), e.getActionCommand(),e.getWhen(),e.getModifiers()));
  else
    super.actionPerformed(e);
};


Comments
Reproducible in 8u20 b26 on Windows 7 x64, not reproducible in 8u11 b12
03-11-2015

please evaluate, does it affect 8u20? 8 GA?
09-02-2015