Only 49 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dislay content of List  RSS feed

 
Kelly KMoni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you Paul, will try that!
Thanks
Kelly
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!