日期:2014-05-20 浏览次数:20675 次
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.event.*; public class TestTableFrame extends JFrame { private JTable table; private DefaultTableModel model; public TestTableFrame() { model = new DefaultTableModel(3, 3); model.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent event) { if (event.getColumn() == 0) { int row = event.getFirstRow(); Object data = model.getValueAt(row, 0); model.setValueAt(data, row, 1); model.setValueAt(data, row, 2); } } }); table = new JTable(model); add(new JScrollPane(table)); } public static void main(String[] args) { JFrame frame = new TestTableFrame(); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
------解决方案--------------------
加监听,当第一列数据改变时,补齐后面两列的数据