i have a JList and an ArrayList.How to bind the datas in arraylist to the jlist.Are the any alternative methods?
ArrayList arl = new ArrayList();
ar
You don't need to clone the ArrayList. Just call toArray()
JList list = new JList(arl.toArray());
ArrayList<String> aList = new ArrayList<String>();
aList.add("blabla");
aList.add("blublu");
aList.add("blibli");
aList.add("bleble");
DefaultListModel<String> model = new DefaultListModel<String>();
for(String s:aList){
model.addElement(s);
}
JList<String> contactList = new JList<String>(model);
Advantage of this is that you can later add/remove elements to already instantiated JList by adding elements to model using methods addElement(Obj o) and removeElement(Obj o).
JList list = new JList(arl.toArray());
JList jList = new JList(arrayList.toArray());
Another option is:
DefaultListModel Jlista = new DefaultListModel();
public Form1() {
jList1.setModel(Jlista);
}
public void yourFunction(){
Jlista.addElement("newElement");
}