Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox item refresh after data update

 
luke lukes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
it worked :-)
 
Lily Tan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luke lukes wrote:it worked :-)

what changes did you make for it to work?
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic