Winston Posted October 9, 2004 Share Posted October 9, 2004 As the thread title says it all, how? thanks. I want to dynamically add items to it. Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted October 9, 2004 Share Posted October 9, 2004 Best way would be to make your own ListModel. ListModel bigData = new AbstractListModel() { public int getSize() { return Short.MAX_VALUE; } public Object getElementAt(int index) { return "Index " + index; } }; JList bigDataList = new JList(bigData); You can replace return "Index " + index; with any returning any type from any data storage type you wish, and remember to replace return Short.MAX_VALUE with the length of your data array. Link to comment Share on other sites More sharing options...
0 Winston Posted October 9, 2004 Author Share Posted October 9, 2004 hmmm isn't there like some way to just add the data into the list? =\ Link to comment Share on other sites More sharing options...
0 tmeg Posted October 9, 2004 Share Posted October 9, 2004 Why "JList", not "List" ? A normal list is used as this List test = new ArrayList(); test.add("Helllo"); But perhaps you mean something different... Link to comment Share on other sites More sharing options...
0 davemania Posted October 9, 2004 Share Posted October 9, 2004 hmmm isn't there like some way to just add the data into the list? =\ If you want to change JList dynamically, you have to use either AbstractListModel or DefaultListModel what data structure are you using for the JList Link to comment Share on other sites More sharing options...
0 davemania Posted October 9, 2004 Share Posted October 9, 2004 public class sampleListModel extends AbstractListModel implements Observer{ POW parser; Element component; Vector result; public unitsListModel(CellMLParser p, Element m){ parser = p; component = m; result = parser.getVect(component); p.addObserver(this); } public int getSize(){ return result.size(); } public Object getElementAt(int n){ Node node = (Node) result.get(n); return node; } public void update(Observable observable, Object object){ result = parser.getVect(component); fireContentsChanged(this,0,getSize()); } } Link to comment Share on other sites More sharing options...
Question
Winston
As the thread title says it all, how? thanks.
I want to dynamically add items to it.
Link to comment
Share on other sites
5 answers to this question
Recommended Posts