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

JComboBox's popup menu should be able to have a different width as the JComboBox

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.1, 1.4.1, 1.4.2
    • client-libs
    • x86
    • linux, windows_2000

      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)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: