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

JComboBox.showPopup() pops list down, not up

XMLWordPrintable

    • swing1.0fcs
    • x86
    • windows_95



      Name: rm29839 Date: 11/12/97


      This is a swing bug as you can probally tell.
      My goal is to write a combo box that the user
      types into, the typed letters are compared to
      the combobox items and if a match is found, the
      combo popup needs to be up and displaying the
      match found.

      The problem is that calling JComboBox.showPopup()
      when the list is already popped up causes the list
      the be popped DOWN.

      This is what I'm doing:

      //insert some necessary imports here

      public class Combo extends JPanel
      {
          JComboBox combo;

          ...

          public Combo()
          {
           combo = new JComboBox();

              ... //add in some items to combo

              combo.setEditable(true);

              combo.setEditor(new SearchComboEditor(combo));

              add(combo, BorderLayout.NORTH);

              ....
          }

          public static void main(String[] args)
          {
      frame = new JFrame("CustomTable");

              Combo ct = new Combo();
      frame.getContentPane().setLayout(new BorderLayout());
      frame.getContentPane().add("Center", ct);
              frame.show();
              ct.requestDefaultFocus();
          }

          // editor for combo list searching
          //Should also add in code to reset selection if edit is unsucessful.
          class SearchComboEditor implements ComboBoxEditor
          {
              JTextField field = new JTextField();
              JComboBox combo;

              SearchComboEditor(JComboBox combo)
              {
                  this.combo = combo;
                  field.addKeyListener(new TypeListener());
              }

              public Component getEditorComponent()
              {
                  return field;
              }

              public void setItem(Object anObject)
              {
                  field.setText(anObject.toString());
              }

              public Object getItem()
              {
                  return field.getText();
              }

              public void selectAll()
              {
                  field.selectAll();
              }

              public void addActionListener(ActionListener l)
              {
                  field.addActionListener(l);
              }

              public void removeActionListener(ActionListener l)
              {
                  field.removeActionListener(l);
              }

              class TypeListener extends KeyAdapter
              {
                  public void keyTyped(KeyEvent e)
                  {
                          combo.showPopup();
                          field.requestFocus();
                  }
              };
          };

      };
      (Review ID: 19472)
      ======================================================================

            duke J. Duke
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: