This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JList Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList Problem" Watch "JList Problem" New topic
Author

JList Problem

MIRANGA_H
Greenhorn

Joined: Jan 27, 2005
Posts: 13
Hello !!!

I wanna load a dynamic list of value to a JList... That means the values that contain in the JList is not constants... it may change !!!
so how do i do this ???
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Call jList1.setListData(array) again.


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
Snoop One
Greenhorn

Joined: Mar 14, 2005
Posts: 5
Hello,
Well you should maybe look in to the model-view-controller architecture of swing.

Very brief intro:
http://www.unknownroad.com/rtfm/swingtut/mvc.html

The swing architecture:
http://java.sun.com/products/jfc/tsc/articles/architecture/

So what you need to do is to use a DefaultListModel as your data model and add any changes on the DefaultListModel object.
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
Reading the API for JList would be a good starting point:

"Simple dynamic-content JList applications can use the DefaultListModel class to store list elements."
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
Originally posted by Pat Hays:
Call jList1.setListData(array) again.


..perhaps writing a ListDataListener would be a slightly more elegant approach!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JList Problem
 
Similar Threads
Regarding JList and DefaultListModel.
Count items in JList
How to add a String array to JList?
JList + Vector
problem selecting JList item