java分栏显示

TableModel dataModel = new AbstractTableModel() {
/**

*/
private static final long serialVersionUID = 1L;


public int getColumnCount() {
return ColumnCount;//设置列数
}


public int getRowCount() {
return RowCount;//设置行数
}


@Override

//设置栏目名称

public String getColumnName(int col) {
String s = null;
if (col == 0) {
s = ColumnName[0];
} else if (col == 1) {
s = ColumnName[1];
} else if (col == 2) {
s = ColumnName[2];
} else if (col == 3) {
s = ColumnName[3];
} else if (col == 4) {
s = ColumnName[4];
}
return s;
}

//设置每一格的内容,每一格都会调用getValueAt,col和row从0开始,自动增加
public Object getValueAt(int row, int col) {
String s = null;
if (col == 0) {
s = row + 1 + "";
} else if (col == 1) {
s = DataName[row];
} else if (col == 2) {
s = DataPath[row];
} else if (col == 3) {
s = DataSize[row];
} else if (col == 4) {
s = DataFileChangedTime[row];
}
return s;
}
};
JTable jt = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(jt);

你可能感兴趣的:(java分栏显示)