JDK-4762915 : JComboBox:prototypeDisplayValue not passed to internal lists PrototypeCellValue
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-10-15
  • Updated: 2017-05-23
Description
Name: jk109818			Date: 10/14/2002


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
service pack 3 installed.

A DESCRIPTION OF THE PROBLEM :
JComboBox has a property: prototypeDisplayValue.
When set, it will not step through every element in the
list to find a proper size.

However, When the drop-down list is first activated (press
the down arrow", the list does walk through every element,
ostensibly to determine a size.  it seems to me that
ComboBox.prototypeDisplayValue should be passed on to the
list.prototypeCellValue, so the list is truely not iterated
for size - ever.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Please see the attached source code for an example

EXPECTED VERSUS ACTUAL BEHAVIOR :
setPrototypeDisplayValue("MMMMMMMM");

Expected Results:
List is not iterated for size -ever.

Actual results:
List is iterated for size for the internal list.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
N/A - No Errors are given.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class ComboProblemPanel extends JPanel
{
  JComboBox jComboBox1 = new JComboBox();

  public ComboProblemPanel()
  {
    try
    {
      jbInit();
    }
    catch(Exception ex)
    {
      ex.printStackTrace();
    }
  }
  void jbInit() throws Exception
  {
    jComboBox1.setPrototypeDisplayValue("WWWWWWWW");
    jComboBox1.setModel(new ShowProblemComboBoxModel());
    this.add(jComboBox1);
  }

  public static void main(String[] args)
  {
    try
    {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    JFrame frame = new JFrame() {
      protected void processWindowEvent(WindowEvent e)
      {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING)
        {
          System.exit(0);
        }
      }
    };
    frame.setSize(new Dimension(200,200));
    frame.validate();
    //Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height)
    {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width)
    {
      frameSize.width = screenSize.width;
    }
    frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
    frame.getContentPane().add(new ComboProblemPanel());
    frame.setVisible(true);
    //Overridden so we can exit when window is closed

  }
}


class ShowProblemComboBoxModel extends DefaultComboBoxModel {
  private static final String[] strings =
{"A","B","C","D","E","F","G","H","I","J","K",
                      "L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z
"};
  public ShowProblemComboBoxModel() {
    super(strings);
  }

  public Object getElementAt(int index) {
    System.out.println("getElementAt has been called! "+index);
    return super.getElementAt(index);
  }

}
---------- END SOURCE ----------

CUSTOMER WORKAROUND :
A work-around is possible, but complicated, as it gets into
the pluggable L&F.  We will be implementing a work-around,
but have not done so yet.
(Review ID: 165773) 
======================================================================

Comments
EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=16773
10-11-2006

EVALUATION The submitter brings up a valid point. The JComboBox prototype value should be used for the internal JList in the BasicComboPopup.getPopupHeightForRowCount() method. The JComboBox prototype value is a bound property so the BasicComboPopup can listen and set the JList prototype value. ###@###.### 2002-10-14
14-10-2002