1 28 29 import javax.swing.table.AbstractTableModel ; 30 31 32 36 public class CustomTableModel extends AbstractTableModel 37 { 38 39 40 43 private String [] columnNames = {"the_city", "id", "name", "street"}; 44 45 48 private Object [][] data = 49 { 50 {"Berne", new Integer (9), "James Schneider", "277 Seventh Av."}, 51 {"Berne", new Integer (22), "Bill Ott", "250 - 20th Ave."}, 52 {"Boston", new Integer (32), "Michael Ott", "339 College Av."}, 53 {"Boston", new Integer (23), "Julia Heiniger", "358 College Av."}, 54 {"Chicago", new Integer (39), "Mary Karsen", "202 College Av."}, 55 {"Chicago", new Integer (35), "George Karsen", "412 College Av."}, 56 {"Chicago", new Integer (11), "Julia White", "412 Upland Pl."}, 57 {"Dallas", new Integer (47), "Janet Fuller", "445 Upland Pl."}, 58 {"Dallas", new Integer (43), "Susanne Smith", "2 Upland Pl."}, 59 {"Dallas", new Integer (40), "Susanne Miller", "440 - 20th Ave."}, 60 {"Dallas", new Integer (36), "John Steel", "276 Upland Pl."}, 61 {"Dallas", new Integer (37), "Michael Clancy", "19 Seventh Av."}, 62 {"Dallas", new Integer (19), "Susanne Heiniger", "86 - 20th Ave."}, 63 {"Dallas", new Integer (10), "Anne Fuller", "135 Upland Pl."}, 64 {"Dallas", new Integer (4), "Sylvia Ringer", "365 College Av."}, 65 {"Dallas", new Integer (0), "Laura Steel", "429 Seventh Av."}, 66 {"Lyon", new Integer (38), "Andrew Heiniger", "347 College Av."}, 67 {"Lyon", new Integer (28), "Susanne White", "74 - 20th Ave."}, 68 {"Lyon", new Integer (17), "Laura Ott", "443 Seventh Av."}, 69 {"Lyon", new Integer (2), "Anne Miller", "20 Upland Pl."}, 70 {"New York", new Integer (46), "Andrew May", "172 Seventh Av."}, 71 {"New York", new Integer (44), "Sylvia Ott", "361 College Av."}, 72 {"New York", new Integer (41), "Bill King", "546 College Av."}, 73 {"Oslo", new Integer (45), "Janet May", "396 Seventh Av."}, 74 {"Oslo", new Integer (42), "Robert Ott", "503 Seventh Av."}, 75 {"Paris", new Integer (25), "Sylvia Steel", "269 College Av."}, 76 {"Paris", new Integer (18), "Sylvia Fuller", "158 - 20th Ave."}, 77 {"Paris", new Integer (5), "Laura Miller", "294 Seventh Av."}, 78 {"San Francisco", new Integer (48), "Robert White", "549 Seventh Av."}, 79 {"San Francisco", new Integer (7), "James Peterson", "231 Upland Pl."} 80 }; 81 82 83 86 public CustomTableModel() 87 { 88 } 89 90 91 94 public int getColumnCount() 95 { 96 return this.columnNames.length; 97 } 98 99 100 103 public String getColumnName(int columnIndex) 104 { 105 return this.columnNames[columnIndex]; 106 } 107 108 109 112 public int getRowCount() 113 { 114 return this.data.length; 115 } 116 117 118 121 public Object getValueAt(int rowIndex, int columnIndex) 122 { 123 return this.data[rowIndex][columnIndex]; 124 } 125 126 127 } 128 | Popular Tags |