• Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseListener to JTable  RSS feed

 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to activate a JDialog box when user double-clicks on any JTable cell. I have added a MouseListener to the JTable but it does not work. The code excerpt is as folows:
studentTableModel.setDataVector(studentData, columnNames);
studentTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
studentTable.setAutoCreateColumnsFromModel(false);
studentTable.setModel(studentTableModel);

studentTable.addMouseListener ( new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
if (me.getClickCount() == 2)
{
Pointp = me.getPoint();
int row= studentTable.rowAtPoint(p);
int col= studentTable.columnAtPoint(p);

String userIDSelected = (String) studentTable.getValueAt(row, 1);

// open a JDialog to show the student status

dialogStatus = new myDialog(dialog, "Kazi", "Number");
dialogStatus.show();
}
}
});

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!