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

    how does one select a JTable row when clicking the right mouse button?

    hi all,

    i would like to know how to select a table row with a right mouse click?

    thanks,
    anonymous.


  2. #2
    Join Date
    Aug 1999
    Location
    Germany, Munich
    Posts
    6

    Re: how does one select a JTable row when clicking the right mouse button?


    table.addMouseListener(new TableMouseListener());
    ...
    class TableMouseListener extends MouseAdapter {
    public void mousePressed(MouseEvent e) {
    JTable table = (JTable)(e.getSource());
    Point p = e.getPoint();
    int row = table.rowAtPoint(p);
    int col = table.columnAtPoint(p);

    // The autoscroller can generate drag events outside the Table's range.
    if ((col == -1) || (row == -1)) {
    return;
    }

    if (SwingUtilities.isRightMouseButton(e)) {
    //for example, do this
    table.setRowSelectionInterval(row, row);
    }
    }
    }




    -JFM


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured