JDK-6257236 : Bug 4177322 should be re-opened (JComboBox popup width)
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-04-19
  • Updated: 2010-05-11
  • Resolved: 2005-11-18
Related Reports
Duplicate :  
Description
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