JDK-4890345 : 1.4.2 REGRESSION: JComboBox has problem in JTable in Windows L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2,1.4.2_04
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-07-14
  • Updated: 2004-10-13
  • Resolved: 2004-09-14
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 JDK 6
1.4.2_07 b01Fixed 6Fixed
Related Reports
Relates :  
Description
Name: jk109818			Date: 07/14/2003


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

FULL OS VERSION :
Windows 2000 5.00.2195 Svc Pack 3

A DESCRIPTION OF THE PROBLEM :
Using the System LnF for Win 2000, and
using Keyboard Navigation only tab to a JTable column that has a DefaultCellEditor using a JComboBox.  Press F2 to activate the editing feature.

There is no way to cause the drop down to appear.  Using the up and down arrow keys we see no movement of the selected item, but when pressing Enter after an arrow key the value has in fact changed.

With the Java LnF pressing the down arrow key after F2 causes the dropdown to appear.  This is the behavior experienced for the Win LnF in sdk 1.4.1.03 and prior.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the example code on a Windows OS.
Using keyboard navigation tab to a cell in the first column.  Press F2.
Now press the down arrow key twice; then press enter.




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Pressing the down arrow key I expect to have the drop down of the JComboBox appear.
ACTUAL -
No visual indication that the selected item is being changed.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.util.Vector;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public class TestBug6 extends JFrame {

    public TestBug6(String name) {
        super(name);

        JTable tbl = new JTable();
        JScrollPane panel = new JScrollPane(tbl);
        TableModel tm = createTableModel();
        tbl.setModel(tm);
        tbl.setRowHeight(20);
        
        JComboBox box = new JComboBox();
        box.addItem("tt");
        box.addItem("ll");
        box.addItem("aa");
        box.addItem("gg");
        box.addItem("zz");
        tbl.getColumnModel().getColumn(0).setCellEditor(
            new DefaultCellEditor(box));

        tbl.setEnabled(true);
        tbl.setCellSelectionEnabled(true);
        getContentPane().add(panel, BorderLayout.CENTER);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        TestBug6 test = new TestBug6("Java LnF TestBug");
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            test = new TestBug6("Native LnF TestBug");
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.pack();
        test.setLocation(100, 70);
        test.setVisible(true);
    }
    
    private TableModel createTableModel(){
        Vector hdr = new Vector();
        hdr.add("One");
        hdr.add("Two");
        Vector data = new Vector();
        Vector row = new Vector();
        row.add("tt");
        row.add("dd");
        data.add(row);
        row = new Vector();
        row.add("ll");
        row.add("jj");
        data.add(row);
        
        return new DefaultTableModel(data, hdr);
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use Windows LnF or revert back to 1.4.1

Release Regression From : 1.4.1_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 190879) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2_07 1.5.0_01 mustang FIXED IN: 1.4.2_07 1.5.0_01 mustang INTEGRATED IN: 1.4.2_07 1.5.0_01 mustang
2004-09-28

SUGGESTED FIX Name: azC76091 Date: 11/06/2003 ------- BasicComboBoxUI.java ------- *** /tmp/sccs.wXa4HG Thu Nov 6 17:45:14 2003 --- BasicComboBoxUI.java Thu Nov 6 17:30:19 2003 *************** *** 1047,1054 **** --- 1047,1058 ---- public void paintCurrentValue(Graphics g,Rectangle bounds,boolean hasFocus) { ListCellRenderer renderer = comboBox.getRenderer(); Component c; + Object selectedItem = comboBox.getSelectedItem(); if ( hasFocus && !isPopupVisible(comboBox) ) { + if(isTableCellEditor) { + selectedItem = listBox.getSelectedValue(); + } c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, *************** *** 1295,1300 **** --- 1299,1308 ---- comboBox.getUI(), BasicComboBoxUI.class); if (key == HIDE) { comboBox.firePopupMenuCanceled(); + if ( ui != null && ui.isTableCellEditor() ) { + ui.popup.getList() + .setSelectedIndex(comboBox.getSelectedIndex()); + } comboBox.setPopupVisible(false); } else if (key == PAGE_DOWN || key == PAGE_UP || ==================================================================== the code for 1.4.2 differs from the Tiger src changes. See the webrev located as follows for the actual changes. http://jpsesvr.sfbay.sun.com:8080/ctetools/html/ViewDetail.jsp?index=1178 ###@###.### 2004-09-03
2004-09-03

EVALUATION Name: azC76091 Date: 11/06/2003 In the Windows L&F when ComboBox with no popup opened receives up or down key it does not open the popup, but changes the combobox's selected value instantly to the previous/next element in the combobox. But when we are in table this situation is handled incorrectly, we are changing the selection in the listbox but when we call repaint() the combobox gets the value to paint from the combobos selection, which is not changes until user does not pressed enter. The idea of suggested fix is to get the selected value from the listbox instead of combobox when JComboBox is placed into the table and no popup is opened. ###@###.### 11/06/2003 ======================================================================
2003-11-06