JTable中怎样获取鼠标所在位置的行数

类别:Java 点击:0 评论:0 推荐:

table=new JTable(cells,columnNames);

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);
                    
                 }
             });

本文地址:http://com.8s8s.com/it/it10025.htm