如果最低行被编辑,有没有办法总是插入一个空行? 我总是希望在底部有一个自由行,如果有人编辑了最低行,则应该自动插入一个新行。
我使用的是AbstractTableModel:
public class NativeTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private ArrayList<Spieler> myObjects = null;
private String[] columnNames = { "Vorname", "Nachname", "Trikotnummer" };
public NativeTableModel() {
myObjects = new ArrayList<Spieler>(JNIResultSet.getMeineSpieler());
}
@Override
public int getRowCount() {
return myObjects.size();
}
@Override
public String getColumnName(int index) {
return columnNames[index];
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public boolean isCellEditable(int row, int col) {
boolean retValue = false;
if (col >= 1) {
retValue = true;
}
return retValue;
}
@Override
public void setValueAt(Object value, int row, int col) {
switch (col) {
case 0:
if (value instanceof String) {
//
}
break;
case 1:
if (value instanceof Integer) {
//
}
break;
}
fireTableCellUpdated(row, col);
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Object value = "";
Spieler s = this.myObjects.get(rowIndex);
switch (columnIndex) {
case 0:
value = s.getVorname();
break;
case 1:
value = s.getNachname();
break;
case 2:
value = s.getTrikotnummer();
break;
}
return value;
}
}
如何检查最低行是否为空,如果为空则插入新行?
答案 0 :(得分:2)
建议: