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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JComboBox is not appearing as it should

Status
Not open for further replies.

msloan

Programmer
May 30, 2001
39
US
I am adding a JComboBox to a JPanel which is added to a JFrame. The code compiles fine and launches as expected, however, when I go to my panel, it looks as if the combo box isn't there. But, when I click where the combo box should be, I get the drop down of selections. I also added an actionListener to print out the selected value, which worked as expected. However, the selected values is not set in the combo box. And if I set the background to white, the combo box shows up, but looks like a textfield - no drop down arrow. Everything else in my panel works fine - buttons, labels, textfields, and tables. Could this have anything to do with the look and feel? I have also tried various sizes for both panel and combo box with no luck.

I am running windows XP Home and using the 1.4.2 JDK.

Any ideas?

Here is a code sample:

Code:
JComboBox cbxTest = new JComboBox(new String [] {"option 1", "option 2", "option3"});
cbxTest.setEditable(false);
cbxTest.setSize(150,20);
cbxTest.setLocation(5,5);
panel.add(cbxTest);
 
What layout manager are you using on the panel that the combo box is on? You're setting location, which means you believe it's a null layout manager, but if you haven't explicity set that, then the results can be unexpected.

Try posting the code that creates the panel as well as the combo box.
 
I will give the layout manager a try - I am not using one currently, so I figured whatever was default, I was using that.
 
thanks for the try, but it isn't that.

I started to play with the layout managers and that got it to appear.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top