table=new JTable(cells,columnNames);(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)
table.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent e)
{
System.out.println("mouseClicked()"); // TODO Auto-generated
// Event stub
// mouseClicked()
System.out.println("row numbers is :"+table.getRowCount());//获取表格的总行数
//获取鼠标点击的行的位置(及行数)
Point mousepoint;
mousepoint =e.getPoint();
System.out.println(table.rowAtPoint(mousepoint)+1);
}
});