swing table 获取鼠标右击的行

来源:互联网 发布:网络电视哪个品牌的好 编辑:程序博客网 时间:2024/04/30 14:42

先创建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); //设置为选中此行 }}});


原创粉丝点击