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
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
posted
0
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.