JDK-4139900 : Default Height of Empty JComboBox
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-05-19
  • Updated: 1999-02-03
  • Resolved: 1999-01-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.2 1.2.2Fixed
Related Reports
Duplicate :  
Description
Name: rk38400			Date: 05/19/98


Hi,

I'm using WinNT v4.0, SP3 with JDK v1.1.6 and Swing v1.0.2.

I'm not 100% sure this is a bug but I think it's definitely a place
where an improvement can be made.  I've included a short sample program
to illustrate the issue.

Let's say I have two JComboBoxes.  One has some text entries in it and
the other is completely empty.  I'm finding that the JComboBox
containing the text entries has a slightly smaller height than the one
without text.  Run the attached program and look closely at the heights
of the two JComboBoxes.

The reason I say this may not be a bug is because there really is no
correct "standard height" for a JComboBox.  When I call
JComboBox.addItem(), I could be adding anything -- not necessarily a
String.

It would seem reasonable, however, to make the "preferred height" equal
to what it would be for a text entry -- since 9 times out of 10 a JComboBox
will probably be used to simply hold text entries.


import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;



class Tester
{
   public static void main(String[] args)
   {
      final JFrame f = new JFrame();

      

      f.addWindowListener(new WindowAdapter()
      {
         public void windowClosing(WindowEvent evt)
         {
            ((Window)evt.getSource()).dispose();
            System.exit(0);
         }
      });
      
      JComboBox cb1 = new JComboBox(),
                cb2 = new JComboBox();
              
      JPanel p = new JPanel(false);
      
      cb1.addItem("Some Item");
      
      p.add(cb1);
      p.add(cb2);
      
      f.getContentPane().add(p, BorderLayout.CENTER);
      
      //--------------------
      // The remaining code simply allows for a change in the LAF....
      //--------------------
      JPanel LAFPanel = new JPanel();

      final JButton windowsLAF = new JButton("Windows"),
                    motifLAF   = new JButton("Motif"),
                    metalLAF   = new JButton("Metal");

      LAFPanel.add(windowsLAF);
      LAFPanel.add(motifLAF);
      LAFPanel.add(metalLAF);

      f.getContentPane().add(LAFPanel, BorderLayout.SOUTH);

      ActionListener LAFListener = new ActionListener()
      {
         public void actionPerformed(ActionEvent evt)
         {
            Object src = evt.getSource();

            try
            {
               if(src == windowsLAF)
                  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
               else if(src == motifLAF)
      	    	   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
               else
      	    	   UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");

               SwingUtilities.updateComponentTreeUI(f);
            }
            catch(Exception e)
            {
               System.err.println("*** ERROR IN CHANGING LAF: " + e);
            }
         }
      };

      windowsLAF.addActionListener(LAFListener);
      motifLAF.addActionListener(LAFListener);
      metalLAF.addActionListener(LAFListener);

      f.setBounds(50, 50, 300, 300);
      f.setVisible(true);
   }
}
(Review ID: 30647)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2.2 swing2.0beta INTEGRATED IN: 1.2.2 swing2.0beta
14-06-2004

EVALUATION I'm marking this as a bug. The empty combo box should come up with a way to intuit a reasonable height. Right now it uses a hard-coded number. tom.santos@eng 1998-05-20 Now, empty combo boxes determine their height based on the space character passed to a DefaultListCellRenderer. It seems to work fine now. tom.santos@eng 1999-01-19
20-05-1998