当前位置: 代码迷 >> J2SE >> JTable表格事件求解,该如何处理
  详细解决方案

JTable表格事件求解,该如何处理

热度:4540   发布时间:2013-02-25 00:00:00.0
JTable表格事件求解
表格中有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();                // 事件处理...            }        }    }
  相关解决方案