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

Editable JComboBox cannot restore previous selection if editing is aborted

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta2
    • generic
    • generic



      Name: boT120536 Date: 03/22/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      With an editable JComboBox, assume the current selected item is "ITEM A", then
      start editing by typing something different, but do NOT type <Enter>, (pretend
      that you changed your mind and still want "ITEM A" to be selected) click
      on "ITEM A" from the drop down list, however the JComboxBox shows the typed-in
      stuff instead of "ITEM A". So selecting the same item does not fire event to
      change selection (which is fine if without editing), but it does not take into
      consideration of aborted editing that has already replace the previous
      selection.

      import javax.swing.*;
      import java.awt.*;
      import java.swt.event.*;

      public class ComboEditorTest extends JFrame {


        public ComboEditorTest() {
          // use a combo box as cell renderer for the 2nd
      column
          JComboBox cb = new JComboBox();
          cb.setEditable(true);
          cb.addItem("ITEM 1");
          cb.addItem("ITEM A");
          cb.addItem("ITEM B");
          cb.addItem("ITEM C");
          cb.setSelectedItem("ITEM A");
          getContentPane().add(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.setLocation(100, 100);
          test.setVisible(true);
        }
      }
      (Review ID: 119323)
      ======================================================================

            peterz Peter Zhelezniakov
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: