1 package org.jdesktop.swing.util; 2 3 import javax.swing.table.AbstractTableModel ; 4 5 10 public class AncientSwingTeam extends AbstractTableModel { 11 12 final String [] names = { "First Name", "Last Name", "Favorite Color", 13 " No.", "Vegetarian" }; 14 15 final Object [][] data = { 16 { "Mark", "Andrews", "Red", new Integer (2), new Boolean (true) }, 17 { "Tom", "Ball", "Blue", new Integer (99), new Boolean (false) }, 18 { "Alan", "Chung", "Green", new Integer (838), new Boolean (false) }, 19 { "Jeff", "Dinkins", "Turquois", new Integer (8), new Boolean (true) }, 20 { "Amy", "Fowler", "Yellow", new Integer (3), new Boolean (false) }, 21 { "Brian", "Gerhold", "Green", new Integer (0), new Boolean (false) }, 22 { "James", "Gosling", "Pink", new Integer (21), new Boolean (false) }, 23 { "David", "Karlton", "Red", new Integer (1), new Boolean (false) }, 24 { "Dave", "Kloba", "Yellow", new Integer (14), new Boolean (false) }, 25 { "Peter", "Korn", "Purple", new Integer (12), new Boolean (false) }, 26 { "Phil", "Milne", "Purple", new Integer (3), new Boolean (false) }, 27 { "Dave", "Moore", "Green", new Integer (88), new Boolean (false) }, 28 { "Hans", "Muller", "Maroon", new Integer (5), new Boolean (false) }, 29 30 { "Rick", "Levenson", "Blue", new Integer (2), new Boolean (false) }, 31 { "Tim", "Prinzing", "Blue", new Integer (22), new Boolean (false) }, 32 { "Chester", "Rose", "Black", new Integer (0), new Boolean (false) }, 33 { "Ray", "Ryan", "Gray", new Integer (77), new Boolean (false) }, 34 { "Georges", "Saab", "Red", new Integer (4), new Boolean (false) }, 35 { "Willie", "Walker", "Phthalo Blue", new Integer (4), 36 new Boolean (false) }, 37 38 { "Kathy", "Walrath", "Blue", new Integer (8), new Boolean (false) }, 39 { "Arnaud", "Weber", "Green", new Integer (44), new Boolean (false) } }; 40 41 protected int rowCount = data.length; 42 43 public AncientSwingTeam() { 44 45 } 46 47 51 public int getColumnCount() { 52 return names.length; 53 } 54 55 public int getRowCount() { 56 return rowCount; 57 } 58 59 60 public Object getValueAt(int row, int col) { 61 return data[row % data.length][col]; 64 } 65 66 public void setValueAt(Object value, int row, int col) { 67 data[row % data.length][col] = value; 68 fireTableCellUpdated(row, col); 69 } 70 71 public String getColumnName(int column) { 74 return names[column]; 75 } 76 77 78 public Class getColumnClass(int c) { 79 Object value = null; 80 if (getRowCount() > 0) { 81 value = getValueAt(0, c); 82 } 83 if (value == null) { 84 return Object .class; 85 } 86 return value.getClass(); 87 } 88 89 90 public boolean isCellEditable(int row, int col) { 91 return true; 92 } 93 94 97 public void insertRows(int rowIndex, int length) { 98 rowCount += length; 99 fireTableRowsInserted(rowIndex, rowIndex + length - 1); 100 } 101 102 105 public void removeRows(int rowIndex, int length) { 106 rowCount -= length; 107 if (rowCount < 0) { 108 length -= rowCount; 109 rowCount = 0; 110 } 111 fireTableRowsDeleted(rowIndex, rowIndex + length - 1); 112 } 113 114 } | Popular Tags |