tags:

views:

131

answers:

1

Hi, I Have a JTable where the data model contains information from a sql query. Want to get the added ability to take me to a new jpanel by double-clicking a row in the jtabel.

Thnx

+3  A: 

You can add a MouseListener to a JTable and then handle the mouseClicked event.

The following code shows a mouseClicked implementation that finds out what row was double clicked. You can then navigate to a panel using this information.

public void mouseClicked(MouseEvent event)
{
  if (event.getClickCount() == 2)
  {
    JTable source = (JTable)event.getSource();
    int rowIndex = source.rowAtPoint(event.getPoint());
    // get data from table model using row index
    // navigate to panel
  }
}
Mark
nice m8te, thnx alot, i'll try it right away.
Rida