我有一个用于制作表格并对在那里输入的数据进行排序的代码。如果我想使用按钮添加一些操作来添加行而不是填充数据并且也可以删除行怎么办。这是我的代码:
public class TableSortDemo extends JPanel {
private boolean DEBUG = false;
class MyTableModel extends AbstractTableModel {
private String[] columnNames = {"Nama",
"NIM",
"IPK"};
private Object[][] data = {
{"", new Integer(0),new Double(0)}
};
public boolean isCellEditable(int row, int col) {
if (col < 2) {
return false;
} else {
return true;
}
}
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value
+ " (an instance of "
+ value.getClass() + ")");
}
data[row][col] = value;
}
private void printDebugData() {
int numRows = getRowCount();
int numCols = getColumnCount();
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + data[i][j]);
}
}
}
}