• 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

JList

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have this search routine which returns a populated ArrayList. I want to display these results in some useful form so that my users can select one or two, scroll through them etc.
I thought a JList would be the sort of thing I wanted, but having read the sun api documentation I am hopelessly confused. (Actually, this documentation always leaves me feeling like this - I mean, why have as their FIRST example of a JList .."
// Create a JList that displays the superclass of JList.class" ??? )
Anyway, what I want to know is how to add each component from the arrayList that I've got, to the JList that's going to display them. I'm missing something, aren't I ? I was really hoping for a .add() method.
Perhaps Yaroslav Chinskiy can help me out - sounds like you have already doen this (very basic) step ??
Thanks,
Kate
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have the ArrayList before you create the JList, use the constructor which takes and Object[]. Use the toArray() method in ArrayList. If the JList is already there, emtpy it out and use setListData(Object[]). Note: if your objects in ArrayList are not Strings, make sure they have a toString() which returns what you want populated in the JList. If that doesn't work create your own DefaultListModel and manipulate it that way. The Sun Tutorial shows how to do that.
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic