• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Dislay content of List

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am new to Swing & Java. I would like to display the content of a List. I used java.util.* components to create this list. Ex:
List l = new ArrayList();
Now I would like to display the content of the List l through the GUI. I was trying to use JList, but JList constructor allows only Vectors. I am wondering how to display the contents of my List using Swing compenents.
Since I am new to Swing & Java, I find it difficult. Please do let me know if you have any suggestions! Thanks in advance for all your help.
Regards
Kelly
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a JList constructor that takes an Object[] as well. Pass your ArrayList into the constructor using the toArray(). The toArray() creates an Object[] from the contents. Make sure your toString() on the Objects within the ArrayList display what you want.
That is the simplest method. Creating your own ListModel is another option.
 
Kelly KMoni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Paul, will try that!
Thanks
Kelly
reply
    Bookmark Topic Watch Topic
  • New Topic