• 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

JComboBox item refresh after data update

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone. i'm trying to develop a little application in which there's a JComboBox that is initialized at start with some elements, retrieved from db: these data are inserted in object, object in a LinkedList, and from this a String array is retrieved to populate the JComboBox. I've added a button that, once clicked, open a JOptionPane in which new data can be added, after that elements are written on db, and the JOptionPane quit. After that, the Linked List above is refreshed, retrieving data from db including new data, and the same procedure of start is repeated for populating JComboBox, but new elements (or also removed elements) are not showed. what can i do?
thanks
LuKe
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use a modifiable combo box model such as a DefaultComboBoxModel. Then you can add or remove elements from the model and the changes will be reflected in the JComboBox that uses this model.
 
luke lukes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it doesn't work. here is the pseudocode:


after closing the window for insert a new user, new items are not displayed in the combobox...



 
luke lukes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it worked :-)
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

luke lukes wrote:it worked :-)


what changes did you make for it to work?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Lily and welcome to the Ranch!

Do you have a problem, and a more specific question, that we can help you with? If it's not directly about adding items to a JComboBox at runtime, then start a new thread.
 
Lily Tan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:Hello Lily and welcome to the Ranch!

Do you have a problem, and a more specific question, that we can help you with? If it's not directly about adding items to a JComboBox at runtime, then start a new thread.



Hi Darryl,

I'm encountering similar problems that's why I'm asking Luke since he solved it
New data are added into the database from a text field.
My combo box does not display the new data unless i terminate and execute the application again.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're asking someone who hasn't posted here in more than a year. To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic