JTable row selection change event
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: JTable row selection change event

  1. #1
    Join Date
    Dec 2000
    Posts
    43

    JTable row selection change event

    How do I get the event in a JTable that a row selection has changed? Assuming that I have the single selection model for the JTable. Thanks.

    jamesyin@pacbell.net



  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: JTable row selection change event

    JTable implements ListSelectionListener, so your table will get a call to its valueChanged(ListSelectionEvent e) method. You can either override this (don't forget to call super.valueChanged()), or if you prefer to be more independent you can add your own ListSelectionListener to the Table's ListSelectionModel, like this:ListSelectionModel rowSM = myTable.getSelectionModel();
    rowSM.addSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
    return; // if you don't want to handle intermediate selections
    ListSelectionModel rowSM = (ListSelectionModel)e.getSource();
    int selectedIndex = rowSM.getMinSelectionIndex();
    ... // do something with selected index
    }
    });
    ...

    Dave

    To email me remove '_spamjam' from my email address
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center