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

Editable ComboBox in JTable does not get edited text as selected item

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • tbd
    • 8u20
    • client-libs

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      A JTable uses an editable JComboBox as editor. When typing text in the combo box and stopping the editor by clicking in another editable cell of the JTable, the text is not committed.

      May be JDK-8032878 is a hint?

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code appended as executable test case.
      Click into the cell "Key 2", select the text and type "Foo" in there.
      Click into the cell "Value 2".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "Foo" should be the value of the cell in (0, 1).
      ACTUAL -
      The value of cell (0, 1) is "Key 2".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class EditableComboBoxInJTable
      {
      public static void main(String[] args)
      {
      JFrame frame = new JFrame();
      frame.setSize(300, 200);
      frame.setLocationRelativeTo(null);
      frame.setLayout(new FlowLayout());
      frame.add(_createTable());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
      }

      private static JTable _createTable()
      {
      JTable table;
      JComboBox<?> comboBox;
      DefaultCellEditor comboEditor;
      JTextField textField;
      DefaultCellEditor textEditor;

      table = new JTable(new String[][]{
      {"Key 1", "Value 1"}, {"Key 2", "Value 2"},
      {"Key 3", "Value 3"}, {"Key 4", "Value 4"}},
      new String[]{"Keys", "Values"});

      comboBox = new JComboBox<String>(new String[]{"Key 1", "Key 2", "Key 3", "Key 4"});
      comboBox.setEditable(true);

      comboEditor = new DefaultCellEditor(comboBox);
      comboEditor.setClickCountToStart(1);

      textField = new JTextField();

      textEditor = new DefaultCellEditor(textField);
      textEditor.setClickCountToStart(1);

      table.getColumnModel().getColumn(0).setCellEditor(comboEditor);
      table.getColumnModel().getColumn(1).setCellEditor(textEditor);

      return table;
      }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              skodandarama Suman Rajkumaar Kodandarama (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: