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

Bug 4177322 should be re-opened (JComboBox popup width)

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      The bug at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4177322 was closed 5 years ago because there was no suggestion for how to fix it. I have a simple solution:

      If the width of any item in the combo box is wider than the box's preferred width, then the combo box popup width should be expanded to the width of the widest item in the combo box, until reaching the combo box's maximum width.

      JUSTIFICATION :
      Currently an ugly workaround is needed to do this simple functionality.


      CUSTOMER SUBMITTED WORKAROUND :
      Add popup listener to combo box:

                  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                      JComboBox box = (JComboBox) e.getSource();
                      Object comp = box.getUI().getAccessibleChild(box, 0);
                      if (!(comp instanceof JPopupMenu)) return;
                      JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
                      Dimension size = new Dimension();
                      size.width = box.getPreferredSize().width;
                      size.height = scrollPane.getPreferredSize().height;
                      scrollPane.setPreferredSize(size);
                      // following line for Tiger
                      // scrollPane.setMaximumSize(size);
                  }
      ###@###.### 2005-04-19 09:08:37 GMT

            kizune Alexander Zuev
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: