File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace and the fly likes JList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "JList" Watch "JList" New topic
Author

JList

kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
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
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.
 
IntelliJ Java IDE
 
subject: JList
 
Threads others viewed
Regarding JList and DefaultListModel.
need help on JList
Adding to a JList, Interface Issue.
JTable & JList
Regarding JList- Combobox Swing
developer file tools