JTable表格事件求解,该如何处理
JTable表格事件求解
表格中有10行记录
我想现在向点击表格中的某行记录 然后触发相应事件
请教下应该触发哪个监听事件?
说明: 是点击JTable中的一行记录触发事件 求解!
------解决方案--------------------
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
}
});
------解决方案--------------------
其实Google下就大把了:
表格中有10行记录
我想现在向点击表格中的某行记录 然后触发相应事件
请教下应该触发哪个监听事件?
说明: 是点击JTable中的一行记录触发事件 求解!
------解决方案--------------------
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
}
});
------解决方案--------------------
其实Google下就大把了:
- Java code
SelectionListener listener = new SelectionListener(jtable); jtable.getSelectionModel().addListSelectionListener(listener); public class SelectionListener implements ListSelectionListener { JTable table; SelectionListener(JTable table) { this.table = table; } public void valueChanged(ListSelectionEvent e) { if (e.getSource() == table.getColumnModel().getSelectionModel() && table.getColumnSelectionAllowed() ){ int firstRow = e.getFirstIndex(); int lastRow = e.getLastIndex(); // 事件处理... } } }