Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add element to existing JList

Tags:

java

swing

jlist

Part of my code

 ArrayList<Item> i = g.getItems(); 
 Vector itemsVector = new Vector(i); 
 JList items = new JList(iemsVector); 

Later in the code I create new object which I want to add to JList. How can I do that?

like image 642
lunar Avatar asked Nov 18 '11 02:11

lunar


1 Answers

private javax.swing.JList<String> list1;
list1.setFont(new java.awt.Font("Tahoma", 0, 24));

DefaultListModel listModel1 = new DefaultListModel();

String st="Working hard";
listModel1.addElement(r);

list1.setModel(listModel1);
like image 75
Wester king Avatar answered Oct 23 '22 12:10

Wester king