Getting the previously selected index for JList

Discussion in 'Java' started by Jared, Jul 31, 2003.

  1. Jared

    Jared Guest

    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

    }

    }
     
    Jared, Jul 31, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    471
  2. =?Utf-8?B?SmFtZXMgUGFnZQ==?=

    previously selected items CheckBoxList

    =?Utf-8?B?SmFtZXMgUGFnZQ==?=, Aug 28, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    420
    =?Utf-8?B?SmFtZXMgUGFnZQ==?=
    Aug 28, 2007
  3. loris_p
    Replies:
    3
    Views:
    10,683
    leafdude
    Nov 28, 2008
  4. loris_p
    Replies:
    2
    Views:
    1,253
  5. mldardy
    Replies:
    0
    Views:
    969
    mldardy
    Sep 28, 2010
Loading...

Share This Page