
II 8.3 Component Methods
! 1 5
Then create the list model object using the javax.swing.DefaultListModel constructor, as
follows:
shoppingListModel = new DefaultListModel() ;
Individual list elements are added to the model using the javax.swing.DefaultList-
Model. addElement method. For example,
shoppingListModel, addElement ("ice axe") ;
The list object itself is created using the javax, swing. JList constructor, as follows:
shoppingList = new JList (shoppingListModel) ;
Note the constructor requires the list model as an argument.
To specify that only one item can be selected from the list at any one time, use the
setSelectionMode ...