Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Adding new element to a Jlist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding new element to a Jlist" Watch "Adding new element to a Jlist" New topic

Adding new element to a Jlist

Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
I have created a Jlist which displays 1 colomn from a Database.
I have stored all the elements in a Vector (Vector Valuelist) and then I did a SetListData.
veldenList.setListData(valueList) ;
Now I want to add new elements to the Jlist using the ActionEventHandler :
private void fielddAdd(java.awt.event.ActionEvent evt) {
// Add your handling code here:
How do I accomplish this ?
I've read that I should use a DefaultListModel but in my case I have used Vectors and a SetListData....
Anybody ?
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
Check the Java Tutorial for the section on using
The List, the ListModel, and the listener are all
in the sample code in the tutorial.
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hi, ucan't directly add or remove an element from a JList, instead use the DefaultListModel class.
DefaultListModel dlm=new DefaultListModel();
JList jlst=new JList(dlm);
Now to add an element to the list:
to remove an element.
Any changes to this model is reflected automatically in the JList.
Happy middling with java.
I agree. Here's the link:
subject: Adding new element to a Jlist
Similar Threads
Difficulty getting a JScrollPane onto a JList box
How can I update the a JList?
Regarding JList- Combobox Swing
Help building a list from a JDBC query
How can you show data from a specific colum in a JList? through JDBC