aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JComboBox item refresh after data update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox item refresh after data update" Watch "JComboBox item refresh after data update" New topic
Author

JComboBox item refresh after data update

luke lukes
Greenhorn

Joined: Feb 04, 2011
Posts: 5
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Feb 04, 2011
Posts: 5
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

Joined: Feb 04, 2011
Posts: 5
it worked :-)
Lily Tan
Greenhorn

Joined: May 01, 2012
Posts: 3
luke lukes wrote:it worked :-)

what changes did you make for it to work?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4543
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Lily Tan
Greenhorn

Joined: May 01, 2012
Posts: 3
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

Joined: May 03, 2008
Posts: 4543
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComboBox item refresh after data update