CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2000

    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.


  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999

    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


    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

On-Demand Webinars (sponsored)

By using this site, you agree to the Privacy Policy