This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JCombobox becomes invisible after adding items to it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JCombobox becomes invisible after adding items to it" Watch "JCombobox becomes invisible after adding items to it" New topic
Author

JCombobox becomes invisible after adding items to it

Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62

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

Joined: Jun 09, 2003
Posts: 4632
> 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


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JCombobox becomes invisible after adding items to it
 
Similar Threads
Selecting an Item in a JComboBox Component with Multiple Keystrokes
Need help in Joining 3 combo boxes
problem in fetching values in combobox from databases.
EventHandling JcomboBox
help on dynamic select box