java - Adding values to a JList -
i have 2 classes, view controls placed gui , 1 code.
but how add values jlist
? can gui class (first class mentioned below) itself, that's not suitable spot.
first class
private jlist userlist; userlist = new jlist(ce.data); // data datalist model in 2nd class
second class (holds future calculations, arrays, etc.)
private string[] testlist; defaultlistmodel data = new defaultlistmodel(); public void addvalueslist() { testlist = new string[] {"user1", "user2"}; (int i=0; < testlist.length; i++) { this.data.add(i, testlijst[i]); } }
the way how justkt laid out. in second class add getter list model (e.g. defaultlistmodel
), create jlist
model (or set after creation of jlist
), add values list model. looks example thing missing setting list model on jlist
. once done jlist pick values add.
so (sorry formatting...):
class testmodel { private defaultlistmodel lm_; public testmodel() { lm_ = new defaultlistmodel(); string[] testlist = new string[] {"user1", "user2"}; for(int i=0; < testlist.length; i++) { lm_.add(i, testlist[i]); } } public listmodel getlistmodel() { return lm_; } } public class test { public test() { testmodel tm = new testmodel(); jlist list = new jlist(tm.getlistmodel()); } }
Comments
Post a Comment