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
| class TableRenderer extends DefaultTableCellRenderer
{
// Cette méthode permet de ' dessiner ' une cellule
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column);
if ((String) value == null || ((String) value).equals(""))
{
this.setBackground( Color.pink );
this.setText( (String)value );
}
else
{
this.setBackground( Color.WHITE );
this.setText( (String)value );
}
return this;
}
}
class TableModel extends AbstractTableModel
{
Vector tableau = new Vector();
Vector cols = new Vector();
public TableModel(Vector tableau, Vector cols)
{
super();
this.tableau = tableau;
this.cols = cols;
}
// Récupérer le nombre de colonne
public int getColumnCount()
{
return cols.size();
}
// Récupérer le nombre de ligne
public int getRowCount()
{
return tableau.size();
}
// Titre d'une colonne
public String getColumnName(int column)
{
return (String)cols.get(column);
}
public Object getValueAt(int rowIndex, int columnIndex)
{
return ((Vector)tableau.get(rowIndex)).get(columnIndex);
}
public Class getColumnClass(int columnIndex)
{
return String.class;
}
} |
Partager