Getting the previously selected index for JList

J

Jared

I've implemented the ListSelectionListener interface for the JList
class, which includes the valueChanged(ListSelectionEvent e) method.

In the valueChanged method, I need to access the previously selected
JList item. Does anybody know how this is done?

My code below demonstrates how I've implemented the valueChanged
method so far. By using getSelectedIndex(), I get the newly selected
JList index. But I don't know how to get the previously selected
index in the valueChanged method.

Thanks!
Jared Hagel


// Handler for list selection changes
public void valueChanged( ListSelectionEvent event )
{
// See if this is a listbox selection and the
// event stream has settled
if (event.getSource() == listbox
&& !event.getValueIsAdjusting() )
{
int selection = listbox.getSelectedIndex();
// do something with selection

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top