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
}
}
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
}
}