Clearing a JList or getting the selected index from a DefaultListModel

Is there any way to clear a JList? I know you can clear a DefaultListModel but I can't get the selected index on a list using DefaultListModel. I need to somehow be able to refresh a list, add new items, then find the index that is selected. Can anyone help me? Thanks in advance.
[288 byte] By [manoya] at [2007-11-26 18:44:13]
# 1

Clearing the model and getting the selected indices are two separate things. It's not the job of the list model to track selection, for starters: that's the job of the ListSelectionModel, although there are convenience methods (like getSelectedIndex()) in JList.

So, to clear the model, either the model has such a method (ex: DefaultListModel does) or you create a new empty model and list.setModel(newModel).

To get the selected index(es), call the appropriate JList method (before you clear the data).

DrLaszloJamfa at 2007-7-9 6:18:08 > top of Java-index,Java Essentials,Java Programming...