Heavyweight popup of the JComboBox is being close on the first show due to unexpected focus lost.

XMLWordPrintable

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: P3
    • None
    • Affects Version/s: 6
    • Component/s: client-libs
    • x86
    • windows_nt, windows_xp

      Try the program below. On the first occurance popup is being closed immediately due to unexpected focus lost event. I have added focus listener to monitor focus change, here is the output:
      << focus goes from: NULL
      >> focus goes to: javax.swing.JComboBox

      -- Frame initialy got focus... After click on combobox:

      << focus goes from: javax.swing.JComboBox
      >> focus goes to: NULL
      << focus goes from: NULL
      >> focus goes to: javax.swing.JComboBox

      -- Here is the problem, due to this focus change popup appears and immediately disappears. Note, thatwhen you second time press the combobox no focus change happens and popup stays on screen.

      -- ComboTest.java

      import javax.swing.*;
      import java.awt.*;
      import java.beans.PropertyChangeEvent;
      import java.beans.PropertyChangeListener;

      public class ComboTest {
          public static class FocusReportListener implements PropertyChangeListener {
              public void propertyChange(PropertyChangeEvent evt) {
                  Object oldF = evt.getOldValue();
                  Object newF = evt.getNewValue();
                  System.out.println("<< focus goes from: "+
                          (oldF == null ? "NULL" : oldF.getClass().getName()));
                  System.out.println(">> focus goes to: "+
                          (newF == null ? "NULL" : newF.getClass().getName()));
              }
          }


          public static void main(String[] args) {
              KeyboardFocusManager.getCurrentKeyboardFocusManager()
                      .addPropertyChangeListener("focusOwner", new FocusReportListener());
              JFrame mainFrame = new JFrame("Test");
              String arguments[] = {"One", "Two", "Three", "Four" };
              JComboBox combo = new JComboBox(arguments);
              mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              mainFrame.setLayout(new BorderLayout());
              mainFrame.add(combo, BorderLayout.CENTER);
              mainFrame.pack();
              mainFrame.setVisible(true);
          }
      }

      -- ComboTest.java
      ###@###.### 2005-05-14 09:58:43 GMT

            Assignee:
            Anton Tarasov (Inactive)
            Reporter:
            Alexander Zuev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: