我正在使用这个类,表格标题显示为 ABCD。
类 CustomTableModel 扩展 AbstractTableModel
{
String[] columnNames = {"FirstName","LastName","Contact","eMail"};<br/>
//private Vector<String> columnNames = new Vector<String>();
private Vector<String[]> data = new Vector<String[]>();
CustomTableModel()
{
String[] a = {"a","s","d","f"};
this.data.addElement(a);
}
public int getColumnCount() {
int columnCount = columnNames.length;
return columnCount;
}
public int getRowCount() {
int rowCount = data.size();
return rowCount;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return data.get(rowIndex)[columnIndex];
}
public Class<?> getColumnClass(int columnIndex) {
return super.getColumnClass(columnIndex);
}
public String getColumnName(int column) {<br/>
return super.getColumnName(column);
}
}
。. . 这就是我为 JTable 创建对象的方式
JTable 表 = 新 JTable(new CustomTableModel());