JDK-4880218 : JComboBox's popup menu should be able to have a different width as the JComboBox
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1,1.4.1,1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux,windows_2000
  • CPU: x86
  • Submitted: 2003-06-18
  • Updated: 2005-09-19
  • Resolved: 2005-09-19
Related Reports
Duplicate :  
Description
Name: rl43681			Date: 06/17/2003


A DESCRIPTION OF THE REQUEST :
If you make a combo box 25 pixels wide because you are trying to save screen
space (The real purpose of the JComboBox compared to JList!), the popup will be only 25 pixels wide.

Developers should be able to set the popup menu to its preferredSize or to another different size than the JComboBox.

As there is no good workaround for this (the better one is to extend BasicComboBoxUI), I suggest to add a new method to JComboBox for setting the size of its popup menu.

JUSTIFICATION :
The real purpose of the JComboBox is to save the space! For the moment we have to either extends the size of our combo boxes, or to extend the Basic UI (which is very ugly and annoying for a multi-LAF application).

I think that extending the popup to its preferred size is perfect, because the popup is temporary.

It wouldn't compromise backward compatibility issue.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
  Programmer should be able to change the popup menu independently to the JComboBox size itself.
ACTUAL -
The popup menu is always the size of the JComboBox.

CUSTOMER SUBMITTED WORKAROUND :
class StyledComboBoxUI extends BasicComboBoxUI
  {
  protected ComboPopup createPopup()
    {
    BasicComboPopup popup = new BasicComboPopup(comboBox)
      {
      protected Rectangle computePopupBounds(int px,int py,int pw,int ph)
        {
        return super.computePopupBounds(px,py,Math.max(comboBox.getPreferredSize().width,pw),ph);
        }
      };
    popup.getAccessibleContext().setAccessibleParent(comboBox);
    return popup;
    }
  }

class StyledComboBox extends JComboBox
  {
  public StyledComboBox()
    {
    setUI( new StyledComboBoxUI() );
    }
  }
(Review ID: 188209) 
======================================================================

Comments
EVALUATION Name: pzR10082 Date: 07/11/2003 There're two possible ways to solve this: * add a method to set popup width (requires new API); * determine popup width based off renderers' preferred sizes (may be time-consuming, also not very flexible). ###@###.### ======================================================================
25-09-2004