Connecting Tech Pros Worldwide Help | Site Map

Swing JList displaying arraylist

Member
 
Join Date: Feb 2008
Posts: 89
#1: 4 Weeks Ago
hi,

I have an arrayList in my program that I want to display in a Jlist. I need the JList to update his contents when the elements in the arraylist change/ an element is added/deleted/...

I'm lost on how to do this. Passing the arrayList as an array into the Jlistconstructor will just display the elements, but no updates will be made according to the API.

Apparently ListDataListeners should be used, and I don't seem to be able to find a nice simple tutorial on how to create these things.

Any help is appreciated. Thanks!
Member
 
Join Date: Feb 2008
Posts: 89
#2: 4 Weeks Ago

re: Swing JList displaying arraylist


I thought I should provide some more info.

I have a program on which I have to build a GUI. I may not change anything inside the program. I can get the arrayList to display using a public inspector from the program and this is the only thing I can use to hook it up to a JList.

I have no clue on how to do this in an easy way. I've googled around, finding info on listeners, events, but I don't see a clear solution.
Member
 
Join Date: Feb 2008
Posts: 89
#3: 4 Weeks Ago

re: Swing JList displaying arraylist


Implementing my own version of ListModel holding an Arraylist did the trick.
Reply