同意LS,实现TableColumnModelListener接口,我给个例子table.getColumnModel().addColumnModelListener( new MyTableColumnModelListener(table));
public class MyTableColumnModelListener implements TableColumnModelListener { JTable table;
// It is necessary to keep the table since it is not possible // to determine the table from the event's source public MyTableColumnModelListener(JTable table) { this.table = table; }
public void columnAdded(TableColumnModelEvent e) { }
public void columnRemoved(TableColumnModelEvent e) { }
public void columnMoved(TableColumnModelEvent e) { System.out.println("column moved"); }
public void columnMarginChanged(ChangeEvent e) { }
public void columnSelectionChanged(ListSelectionEvent e) { } }
由于JTable已经实现了TableColumnModelListener接口,所以只需重写columnMoved方法就可以对事件进行处理了
new MyTableColumnModelListener(table));
public class MyTableColumnModelListener implements TableColumnModelListener {
JTable table;
// It is necessary to keep the table since it is not possible
// to determine the table from the event's source
public MyTableColumnModelListener(JTable table) {
this.table = table;
}
public void columnAdded(TableColumnModelEvent e) {
}
public void columnRemoved(TableColumnModelEvent e) {
}
public void columnMoved(TableColumnModelEvent e) {
System.out.println("column moved");
}
public void columnMarginChanged(ChangeEvent e) {
}
public void columnSelectionChanged(ListSelectionEvent e) {
}
}