Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about JComboBox

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic