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
|
public class HeaderCellRenderer implements TableCellRenderer{
/** Label used to display the text and colour of the cell */
private JLabel l = new JLabel();
public HeaderCellRenderer(){
l.setOpaque(true);
}
/**
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// gestion de la police de caractères des cellules
if (row==0 || column==0){
l.setFont(new Font("SansSerif",Font.BOLD,11));
}
else{
l.setFont(new Font("SansSerif",Font.PLAIN,11));
}
// gestion des cellules entête
if (startPosition != -1 && column>=startPosition && column<startPosition+colors.length){
//couleurs
l.setBorder(BorderFactory.createMatteBorder(4,4,4,4,colors[column-startPosition]));
}
else{
l.setBorder(null);
}
l.setToolTipText(value.toString());
l.setHorizontalAlignment(JLabel.CENTER);
l.setVerticalAlignment(JLabel.CENTER);
l.setText(value.toString());
return l;
}
} |
Partager