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