how-to

Window (swing) applications

How to add items to JList

Adding items into new model. Current context will be overriden:

/* -- create and set new model */

DefaultListModel m = new DefaultListModel();

list1.setModel( m );

/* -- add elements */

m.addElement( "item 1" );
m.addElement( "item 2" );

It shows: