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


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -