在这里,我想使用构造函数动态分配表中的行数。datamodel 是类,datamodel(int count) 方法分配行数。
import javax.swing.table.AbstractTableModel;
@SuppressWarnings("serial")
public class datamodel extends AbstractTableModel{
int row1;
datamodel(int count){
row1 = count;
count = 0;
}
private String[] columnNames = {"Sl No","Material Code", "Material Name", "Select", "Received QTY", "Unit", "To Be Delivered", "PO No", "PO Sl"};//new String[9];
//table has 100 rows and 9 columns
private Object[][] data = new Object[row1][9];
public int getColumnCount() { return columnNames.length; }
public int getRowCount() { return data.length;}
public String getColumnName(int col) {
// TODO Auto-generated method stub
return columnNames[col];
}
public Object getValueAt(int row, int col) {
// TODO Auto-generated method stub
return data[row][col];
}
@Override
public void setValueAt(Object aValue, int row, int col) {
// TODO Auto-generated method stub
data[row][col] = aValue;
fireTableCellUpdated(row, col);
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
return true;
}
public Class getColumnClass(int col) {
if((col == 4) || (col == 6))
return Double.class;
//return getValueAt(0, c).getClass();
else if(col == 3)
return Boolean.class;
else
return String.class;
}
}
这是一个抽象表模型,我想将行数传递给数据模型。