Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Refreshing a JList

843805Mar 3 2007 — edited Mar 4 2007
Hi everyone,

I have an array list which populates a JList from my database. When I insert a new entry into my database it will update my JList correctly with that new entry.

However, when I delete or update from my database I can only get my JList to display all my records twice except for the ones I either updated or deleted.

What I need to know is how to clear my JList without getting a nullPointer Exception and refill my JList with the new updated data...

I'll show you how I populate my JList after I make an insert into the database....
((AddPanel) tab2).addInsertActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e)
					{
						data_model.insert(((AddPanel) tab2).getSubject(), ((AddPanel) tab2).getMessage());
						DefaultListModel list_model = ((DisplayPanel) tab1).getListModel();
					    for (ListElement elt : data_model.getElementList()) {
					    	if (! list_model.contains(elt)){
					    		list_model.addElement(elt);
					    		System.out.println(">>Inserted new message: " + elt.getSubject());
					    	}
					    }
					}
				});
Any help would be appreciated!

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 1 2007
Added on Mar 3 2007
4 comments
456 views