今天折腾了这个事件监听了很久,重新定义jtable 继承mouselistener还是监听不到效果,最后发现这段代码很管用,直接在生成的jtable上添加mouseListenner类:
//给table加上一个鼠标事件监听器对象
table.addMouseListener(new java.awt.event.MouseAdapter(){
publicvoid mouseClicked(MouseEvent e) {//仅当鼠标单击时响应
//得到选中的行列的索引值
int r= table.getSelectedRow();
int c= table.getSelectedColumn();
//得到选中的单元格的值,表格中都是字符串
Object value= table.getValueAt(r, c);
String info=r+"行"+c+"列值 : "+value.toString();
javax.swing.JOptionPane.showMessageDialog(null,info);
}
}); 在这个内部类中添加了mouseadaper这个类,这是没有注意的。