Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding new element to a Jlist

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
Thanks,
Kristof
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the Java Tutorial for the section on using
Lists.
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
The List, the ListModel, and the listener are all
in the sample code in the tutorial.
HTH,
Joe
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
dlm.addElement(element);
&
dlm.removeElement(element);
to remove an element.
Any changes to this model is reflected automatically in the JList.
Happy middling with java.
Netharam
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic