I have written a "double-click" event on my JTable
. My JTable, viz. myTaskTable is populated with a number of rows having multiple columns. I want the row index to be retrieved when I double click on one of the rows of the JTable
. I am not sure why is it always returning me an index of -1 resulting in an exception. Am I am overlooking something? What could be going wrong?
This is how I am retrieving the index of the selected row from the JTable
- myTaskTable
int selRow = myTaskTable.getSelectedRow();
Thank you!
Edit
Here is the code:
...
myTaskTable.addMouseListener(this);
...
public void mouseClicked(MouseEvent e)
{
if(e.getModifiers() == MouseEvent.BUTTON1_MASK)
{
if(e.getClickCount() == 2)
{
e.consume();
int selRow = myTaskTable.getSelectedRow();
System.out.println("GridReport double clicked on row="+selRow);
}
}
}