Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Items disappearing in JComboBox

Status
Not open for further replies.

tom62

Programmer
Nov 12, 2002
152
0
0
DE
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

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);
	}
}
 
The problem seems to be related to my Nvidia screen driver or XP screen settings, because the problem doesn't occur on my laptop and other PC's.
 
I've found it! Is was indeed my nvidia video driver that caused the strange behaviour.

The problem disappeared when I added the following VM argument: -Dsun.java2d.d3d=false
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top