• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JCombobox becomes invisible after adding items to it

 
Paras Ahuja
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi everyone,
I have two comboboxes cb[0] and cb[1] stored in a file. The contents of cb[1] depend on the selected item of cb[0] as follows:


Now, i have another class to add items to either of the boxes (cb[0] or cb[1]). To add item to cb[1], first you have to select the cb[0] item ( hope you undestand why). After doing everything, i save the boxes in the same file from which i retrieve them.
Now the problem is, even after trying to add an item to cb[1], when i run the class that displays the comboboxes, making any change on cb[0] makes cb[1] invisible.
Can't undertsnad why? Please help.....
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Please help.....

you would need to post a small demo program that displays the problem.

this shouldn't affect anything, but might, depending on the rest of the code
if(sel.equals("Wired")); //<------remove the semi-colon (from both if's)

the (better) way of changing the contents of the combo is
DefaultComboBoxModel model = new DefaultComboBoxModel();
add all the items to the model
cb[1].setModel(model);

you could even pre-load the various models, then just set them if selected


 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic