TableEventHandle 实现TableModelListener接口,实现如下方法:tableChanged(TableModelEvent e)。该方法由fireTableCellUpdated(row, col)触发。将fireTableCellUpdated(row, col)放到setValueAt(),就可以做到,当表格的值有改变时,调用fireTableCellUpdated,触发TableModelEvent事件,然后做相应处理。
package tableModelListenerTest;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
public class TableEventHandle implements TableModelListener {
JTable table = null;
MyTable mt = null;
JLabel label = null;
public TableEventHandle() {
JFrame f = new JFrame();
mt = new