Whenever I add a JComboBox to a JFrame of JDialog, the items in the JComboBox becomes invisible (but still selectable) when the width of the JComboBox becomes "too" large. That happens under the standard Metal and Nimbus LF, but not under the Windows LF. I'm using Java 6.18 and my PC is running under Windows XP with Service Pack 3.
I Googled for the problem, but so far I haven't found a solution.
Here follows a simple example
I Googled for the problem, but so far I haven't found a solution.
Here follows a simple example
Code:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class TomTest extends JFrame {
public TomTest() {
JComboBox jComboBox = new JComboBox();
// still works with jComboBox.setPreferredSize(new Dimension(150, 25));
jComboBox.setPreferredSize(new Dimension(151, 25));
for(int i = 0; i < 3; i++) {
jComboBox.addItem(i);
}
getContentPane().setLayout(new BorderLayout());
getContentPane().add(jComboBox, BorderLayout.CENTER);
pack();
}
public static void main(String[] args) {
TomTest frame = new TomTest();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}