加入鼠标事件之后,如何通过MouseEvent get到要选择的行呢?
解决方案 »
- 请用Swt designer的朋友请进,新建一个JFrame出错。高分求救。晚上结贴。
- 老话重提: 我看 forward 和redirect的区别,请高人check
- 简要描述开发过程中close()方法关闭流的原因
- 请问在resion底下运行jsp页面的时候,为什么自动修改<title></title>之间的中文字符?
- 一个正则表达式的问题,在线等..
- 甩80分,请知道的朋友帮菜鸟一下。
- Java串口通讯 遇到问题,求帮助!
- 环境变量问题 急!!
- 哪为大哥帮我XML文件显示到一个是树上
- 判断字符数组是否为空?
- 高分求助:哪位大虾开发过银行接口,网上支付?
- 为什么要用Serializable 类,有什么好处呢?
//这里可以判断鼠标的右键 还是左键 ,以及e.getClickCount来判断次数。
//这样可以对不同的情况作不同的处理。
//下面的就是一个大概的意思。
int col = tblParameter.columnAtPoint(e.getPoint());
int row = tblParameter.rowAtPoint(e.getPoint());
tblParameter.setRowSelectionInterval(row,row+1);
}
1。首先捕获鼠标事件,判断是你像要的(比如右键点击两次等等)。
2。通过MouseEvent e变量的e。getPoint得到鼠标的位置point.
3。用JTable.rowAtPoint(Point)和
JTable.columnAtPoint(point)方法得到鼠标所在的行和列的标号。
4。利用JTable.setRowSelectionInterval
和JTable.setColumnSelectionInterval方法去控制像要选取的行和列。当然,第四步的效果与你的JTable所设置的选取模式相关。下面是两个方法的帮助文档:
================================
setRowSelectionInterval
public void setRowSelectionInterval(int index0,
int index1)
Selects the rows from index0 to index1, inclusive. Parameters:
index0 - one end of the interval
index1 - the other end of the interval
Throws:
IllegalArgumentException - if index0 or index1 lie outside [0, getRowCount()-1]--------------------------------------------------------------------------------setColumnSelectionInterval
public void setColumnSelectionInterval(int index0,
int index1)
Selects the columns from index0 to index1, inclusive. Parameters:
index0 - one end of the interval
index1 - the other end of the interval
Throws:
IllegalArgumentException - if index0 or index1 lie outside [0, getColumnCount()-1]