don't need 通过鼠标点击的位置信息换算JTable.addMouseListener(
new MouseAdapter(){
public void mouseClicked(MouseEvent event){
if(table.getSelectedRowCount()==1){ //mouse click cannot select
//more than one row
int row=table.getSelectedRow();
.....
new MouseAdapter(){
public void mouseClicked(MouseEvent event){
if(table.getSelectedRowCount()==1){ //mouse click cannot select
//more than one row
int row=table.getSelectedRow();
.....
JTable.rowAtPoint(Point p);这个Point怎么来的就不用说了吧
自己很土地实现了一个,贴出来留个纪念^_^ /**
* 获取鼠标点击的行号
* @param y 点击位置的纵坐标值
* @return 行号
*/
private int getClickedRow(int y) {
// JTable的行总数
int rowCount = table.getRowCount();
// JTable行的累计纵坐标
int rowY = 0; if (y < 0) {
return -1;
}
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
rowY = rowY + (int) table.getCellRect(rowIndex, 0, true).getHeight();
if (y < rowY) {
return rowIndex;
}
} return -1;
}