swing table 获取鼠标右击的行
先创建Point类获取鼠标位置
再通过表格的rowAtPoint方法来获取点击的行
通过setRowSelectionInterval选择点击此行
部分代码
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e){
if (e.getButton() == MouseEvent.BUTTON3){
Point mousepoint;
mousepoint =e.getPoint(); //获取鼠标位置
int k = table.rowAtPoint(mousepoint); //此方法返回行号
table.setRowSelectionInterval(k,k); //设置为选中此行
}
}
});
还没有评论,来说两句吧...