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 A question about JComboBox 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 "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,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about JComboBox
 
Similar Threads
NetBeans Matisse JCombBox Event Listener
JComboBox and ItemListener
Prevent user from changing display item in JComboBox ?
Editable JComboBox w. JDialogBox
JComboBox and Mac