table = new JTable(model);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(final MouseEvent arg0) {
int row = table.getSelectedRow(); // 获得当前选中的行号
ID = table.getValueAt(row, 0);
System.out.println(ID);
}
}); 这是在表格模型中做的单击表格任意行时,左键事件,现在要求在这个基础上,实现右键事件,如何实现?
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(final MouseEvent arg0) {
int row = table.getSelectedRow(); // 获得当前选中的行号
ID = table.getValueAt(row, 0);
System.out.println(ID);
}
}); 这是在表格模型中做的单击表格任意行时,左键事件,现在要求在这个基础上,实现右键事件,如何实现?
解决方案 »
- 字符串“Mon Dec 31 00:00:00 CST 2012”转换成日期问题?
- 求助!now,,爲什麽沒有輸出結果啊
- 请问一下线程池,是如何对多个任务重用线程的?是如何实现重用的?
- 紧急求助!!!!如何给JTextField设置监听事件
- 谁给我一个文件上传的包
- 菜鸟求救:我的Applet为什么在浏览器中无法运行?
- 打开IE窗口运行我自己写的applet,为什么我关闭了运行该applet的ie窗口后,aplet还在运行?
- 一个方法调用可能很复杂的问题?
- 不理解,真的不理解!!!!
- 我想用java 编个基于WEB的聊天室程序,可以给个算法吗?
- 怎样安装jdk
- 大家好,帮我调试一下这个程序好吗?关于对象克隆的
if (SwingUtilities.isRightMouseButton(e)) {
int row = table.getSelectedRow(); // 获得当前选中的行号
ID = table.getValueAt(row, 0);
System.out.println(ID);
}
}
例如:
public void tableRecord_mouseClicked(MouseEvent e) {
// 3 代表右键
if (e.getButton() == 3) {
//这里写你需要实现的功能,例如:
JOptionPane.showMessageDialog(this, "我是右键!");
}
}
if (SwingUtilities.isRightMouseButton(e)) {
int row = table.getSelectedRow(); // 获得当前选中的行号
ID = table.getValueAt(row, 0);
System.out.println(ID);
}
}
// MouseEvent.Button3 代表右键
if (e.getButton() == MouseEvent.Button3 ) {
//这里写你需要实现的功能,例如:
JOptionPane.showMessageDialog(this, e.getX(),e.getY());
//this需替换成你要在哪个组件上显示的名称
//e.getX(),e.getY()分别为横坐标和纵坐标
}
}