-
Notifications
You must be signed in to change notification settings - Fork 1
/
tableModel.java
73 lines (57 loc) · 1.95 KB
/
tableModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class tableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private List<String[]> records;
public tableModel(List<String[]> records) {
this.records = records;
}
public void addTheseRows(List<String[]> new_data) {
for(int i = 0; i < new_data.size(); ++i) {
//System.out.println(new_data.get(i));
records.add(new_data.get(i));
fireTableDataChanged();
}
}
public String getName(int row)
{
return records.get(row)[1];
}
public void deleteAllRows(){
//System.out.println(this.getRowCount());
for(int i = this.getRowCount()-1; i >= 0; --i ) {
records.remove(i);
fireTableRowsDeleted(i, i);
}
//System.out.println("after" + Integer.toString(this.getRowCount()));
}
public int getColumnCount() {
// return however many columns you want
return 4;
}
public int getRowCount() {
return records.size();
}
public String getColumnName(int columnIndex) {
switch (columnIndex) {
case 0: return "Sr. No.";
case 1: return "Name";
case 2: return "College";
case 3: return "Branch";
default : return "Column out of range";
// ...
}
}
public String getValueAt(int rowIndex, int columnIndex) {
String[] student_rec = records.get(rowIndex);
// System.out.println(student_rec[3]);
switch (columnIndex) {
case 0: return student_rec[0];
case 1: return student_rec[1];
case 2: return student_rec[2];
case 3: return student_rec[3];
default : return "Error";
// ...
}
}
}