unable to add elements in jlist
UNable to add elements in jlist
in constructor
getting jlist blank
following is my code :
Code :
private Server ser=null;
Thread my=null;
DefaultListModel clients= new DefaultListModel();
public UIServer(Server ser) {
initComponents();
this.ser=ser;
setVisible(true);
clients = new DefaultListModel();
for(int i=0;i<=ser.clientsNames.length-1;i++)
{
clients.addElement(ser.clientsNames[i]);
}
lstClient = new JList(clients);
lstClient.setModel(clients);
my= new Thread(this);
//my.start();
}
I debugged and im getting values in list model and im using netbeans IDE
Re: unable to add elements in jlist
Please make a small complete program that compiles, executes and shows the problem.
Re: unable to add elements in jlist
Code :
class UIServer extends JFrame{
private Server ser=null;
Thread my=null;
DefaultListModel clients= new DefaultListModel();
public UIServer(Server ser) {
initComponents();
this.ser=ser;
setVisible(true);
clients = new DefaultListModel();
for(int i=0;i<=ser.clientsNames.length-1;i++)
{
clients.addElement(ser.clientsNames[i]);
}
lstClient = new JList(clients);
lstClient.setModel(clients);
add(lstClient);
setvisible(true);
}
}
class Server{
public String clientsNames[]={"02","05","10","11","24","28","29","37","43","86"};
public Server(){UIServer o = new UIServer(this);}
}
Re: unable to add elements in jlist
The posted code will not compile without import statements for the classes that are used.
There is no main() method needed to execute the class.