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();
                  .....

解决方案 »

  1.   

    楼上你。。
    JTable.rowAtPoint(Point p);这个Point怎么来的就不用说了吧
      

  2.   

    谢谢relive,昨天愣是没注意到rowAtPoint这个函数,结果绕了一大圈
    自己很土地实现了一个,贴出来留个纪念^_^  /**
       * 获取鼠标点击的行号
       * @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;
      }