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
|
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
if (increasing) {
// l.setBorder(BorderFactory.createMatteBorder(4,4,4,4,colors[column-startPosition]));
// l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,
// colors[column-startPosition], colors[column-startPosition]));
l.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createBevelBorder(BevelBorder.RAISED, colors[column-startPosition], Color.darkGray),
BorderFactory.createMatteBorder(2,2,3,3,colors[column-startPosition])));
}
else {
// l.setBorder(BorderFactory.createMatteBorder(4,4,4,4,colors[colors.length-(column-startPosition)-1]));
l.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createBevelBorder(BevelBorder.RAISED, colors[colors.length-(column-startPosition)-1], Color.darkGray),
BorderFactory.createMatteBorder(2,2,3,3,colors[colors.length-(column-startPosition)-1])));
}
}
else{
l.setBorder(null);
}
l.setToolTipText(value.toString());
l.setHorizontalAlignment(JLabel.CENTER);
l.setVerticalAlignment(JLabel.CENTER);
l.setText(value.toString());
return l;
}
} |
Partager