Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6559152

editable JComboBox: Can't select with keys inside JTable

XMLWordPrintable

    • b96
    • 6
    • b15
    • x86
    • windows_xp
    • Verified

        FULL PRODUCT VERSION :
        1.6.0_01

        ADDITIONAL OS VERSION INFORMATION :
        Linux (Suse 10.1), Windows XP

        A DESCRIPTION OF THE PROBLEM :
        Using java 1.6:
        - A JComboBox as a CellEditor in a JTable
        - The JComboBox is editable
        - The items in the ComboBox are not Strings
        I can't select an entry from the list using the cursor keys and return (the mouse works).

        This worked in java 1.4 and 1.5 .

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Start the test program. Click into the Table. Use the cursor keys to select "2". Hit enter.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The "2" should be selected.
        ACTUAL -
        The "1" is selected.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package test;

        import java.util.Vector;

        import javax.swing.DefaultCellEditor;
        import javax.swing.JComboBox;
        import javax.swing.JFrame;
        import javax.swing.JTable;
        import javax.swing.table.DefaultTableModel;

        public class Test extends JFrame {

        public Test() {
        BoxItem item1 = new BoxItem("1");
        BoxItem item2 = new BoxItem("2");

        DefaultTableModel model = new DefaultTableModel(new Object[][] {{item1}}, new String[] {"test"});
        JTable table = new JTable(model);

        Vector v = new Vector();
        v.add(item1);
        v.add(item2);

        JComboBox box = new JComboBox(v);
        box.setEditable(true);
        table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(box));

        getContentPane().add(box);
        pack();
        }


        static class BoxItem {

        String s = null;

        public BoxItem(String s) {
        this.s = s;
        }

        public String toString() {
        return s;
        }
        }

        public static void main(String[] args) {
        Test t = new Test();
        t.setVisible(true);
        }

        }

        ---------- END SOURCE ----------
        It is copied from the description of 6557820:
        FULL PRODUCT VERSION :
        java version "1.6.0"
        Java(TM) SE Runtime Environment (build 1.6.0-b105)
        Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]
        Microsoft Windows 2000 [Version 5.00.2195]


        A DESCRIPTION OF THE PROBLEM :
        In an editable combo box inside a JTable, when using the keyboard, presing enter or the space bar doesn't select the highlighted item. This worked with JDK 1.5.0.08.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Select the editable combo box
        click esc to open the drop down list
        using the arrow keys highlith one of the items
        press enter (or space)

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The highlighted item should be selected
        ACTUAL -
        with enter the list is closed and nothing is selected, with the spacebar nothing happens.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.DefaultCellEditor;
        import javax.swing.table.TableColumn;
        import javax.swing.table.TableColumnModel;
        /*
         * Test.java
         *
         * Created on May 3, 2007, 1:29 PM
         */

        /**
         *
         * @author helm-youngs
         */
        public class Test extends javax.swing.JFrame {
            
            /** Creates new form Test */
            public Test() {
                initComponents();
                getContentPane().add(scrollPane);
                pack();
            }
            
            /** This method is called from within the constructor to
             * initialize the form.
             * WARNING: Do NOT modify this code. The content of this method is
             * always regenerated by the Form Editor.
             */
            private void initComponents() {//GEN-BEGIN:initComponents
                editableComboBox = new javax.swing.JComboBox();
                scrollPane = new javax.swing.JScrollPane();
                testTable = new javax.swing.JTable();
                
                editableComboBox.setEditable(true);
                editableComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
                
                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                setTitle("Test");
                testTable.setModel(new javax.swing.table.DefaultTableModel(
                    new Object [][] {
                        {null, null, null, null},
                        {null, null, null, null},
                        {null, null, null, null},
                        {null, null, null, null}
                },
                    new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
                }
                ));
                TableColumnModel columnModel = testTable.getColumnModel();
                TableColumn tableColumn = columnModel.getColumn(0);
                tableColumn.setCellEditor(new DefaultCellEditor(editableComboBox));
                scrollPane.setViewportView(testTable);
            }//GEN-END:initComponents
            
            /**
             * @param args the command line arguments
             */
            public static void main(String args[]) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        new Test().setVisible(true);
                    }
                });
            }
            
        // Variables declaration - do not modify//GEN-BEGIN:variables
            private javax.swing.JComboBox editableComboBox;
            private javax.swing.JScrollPane scrollPane;
            private javax.swing.JTable testTable;
        // End of variables declaration//GEN-END:variables
            
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        using alt+up or down arrow selects the highlited item.

        Release Regression From : 5.0u11
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

              mlapshin Mikhail Lapshin (Inactive)
              ryeung Roger Yeung (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: