java - Adding elements to a JList -
i have array of objects contain name of customers, this: customers[]
how can add elements existing jlist automatically after press button? have tried this:
for (int i=0;i<customers.length;i++) { jlist1.add(customers[i].getname()); }
but mistake. how can solve that? working on netbeans. the error appears "not suitable method found add(string). way method getname returning name of customer in string.
the add
method using container#add
method, not need. need alter listmodel
, e.g.
defaultlistmodel<string> model = new defaultlistmodel<>(); jlist<string> list = new jlist<>( model ); ( int = 0; < customers.length; i++ ){ model.addelement( customers[i].getname() ); }
edit:
i adjusted code snippet add names directly model. avoids need custom renderer