0

How can I update my listbox contents?

asked 2011-02-13 14:04:45 +0800

parascus gravatar image parascus
93

Hi,

I have a Listbox filled with rows loaded from a database table. If there are changes in the table (deletions, modifications or additions of rows) I'd like to update my window by a method in java (somethings like refresh, redraw, invalidate). But it seems that the only possiblity is to remove the listbox and recreate it totally. Am I correct?

Stephan

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2011-02-13 14:51:30 +0800

Matze2 gravatar image Matze2
773 7

A call to setModel() should do it. From the Javadoc:

* Sets the list model associated with this listbox. If a non-null model is
* assigned, no matter whether it is the same as the previous, it will
* always cause re-render.

link publish delete flag offensive edit

answered 2011-02-13 15:12:43 +0800

parascus gravatar image parascus
93

Hi Matze2,

thank you for your reply. I tried it with "list.setModel(list.getListModel());" directly after the change has been saved to the database table. This didn't work, maybe because it was exactly the same as previous. But by defining a new ListModel with the same data loaded from the database it worked (list.setModel(new SimpleListModel(getAllRecords()));).

Stephan

link publish delete flag offensive edit

answered 2012-08-21 14:20:09 +0800

vegaua gravatar image vegaua
21

Thankx. It realy works

link publish delete flag offensive edit

answered 2012-08-21 15:55:55 +0800

danielgoodwin gravatar image danielgoodwin
76 2

updated 2012-08-21 15:56:13 +0800

You could also just update that particular item in the list model (if the retrieval of the list model data itself is expensive)

Something like


ListModelList lml = (ListModelList) listBox.getListModel();

int idx = lml.indexOf(obj);
if (idx != -1) {
{
	lml.set(idx,obj);
}

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-02-13 14:04:45 +0800

Seen: 161 times

Last updated: Aug 21 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More