aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes A question about JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A question about JComboBox" Watch "A question about JComboBox" New topic
Author

A question about JComboBox

George Ren
Ranch Hand

Joined: Aug 17, 2002
Posts: 58
Hi, everyone!
I create a JComboBox object that contains several items, this JComboBox is displayed in a JDialog oject. The user can select the items when the JDialog object is displayed. And I discover that when user close the dialog then open the dialog again, the default display item is not the one the user selected last time. I want to display the item that user select last time in a JComboBox as a default item. How can I do that?

Thanks!

Regards,


THINK!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What you discovered is the correct way it should work. There is no reason a JComboBox should remember your last selection, especially when you have destroyed the object (by destroying the JDialog) and created a brand new object when you created a new JDialog.

You have a couple of options here.

1. Save the selected item in some way (memory, properties file, etc) and then load that item when you open a new JDialog and set the JComboBox appropriatly.

2. When you "close" the JDialog, do not call dispose(), just setVisible(false). Then, when you go to open a new one, don't do "new" just do setVisible(true).


GenRocket - Experts at Building Test Data
George Ren
Ranch Hand

Joined: Aug 17, 2002
Posts: 58
But I think when the user want to set the parameters, he/she should be noticed that his/her last modification is what. Anyway, thanks very much for ur help

Regards,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question about JComboBox