Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about JComboBox

 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic