我正在使用JTable:
public class MyPanel extends JPanel {
public MyPanel () {
init()
}
init () {
DataModel model = new DataModel();
JTable table = new JTable (model);
TableColumnModel tcm = agentsTable.getColumnModel();
tcm.getColumn(FIRST).setPreferredWidth(15);
tcm.getColumn(SECOND).setPreferredWidth(100);
tcm.getColumn(THIRD).setPreferredWidth(200);
JScrollPane scroller = new JScrollPane();
scroller.getViewport().add(table);
this.add(scroller, BorderLayout.CENTER);
}
}
public class DataModel extends AbstractTableModel {
public final static int FIRST = 0;
public final static int SECOND = 1;
public final static int THIRD= 2;
...
}
问题是每次我向模型添加一行时,TableColumnModel似乎都会返回默认值,并且所有列都具有相同的宽度