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
|
class DemoCellRenderer extends JLabel implements TableCellRenderer {
boolean isBordered = true;
Color selectedForeground = null;
Color selectedBackground = null;
Color unselectedForegroundAlt = null;
Color unselectedBackgroundAlt = new Color( 255, 255, 255 );
Color unselectedForeground = null;
Color unselectedBackground = null;
public DemoCellRenderer() {
super();
setOpaque(true);
}
//pour remplir le tableau
public Component getTableCellRendererComponent(
JTable table, Object val,
boolean isSelected, boolean hasFocus,
int row, int column) {
setAlignmentX( CENTER_ALIGNMENT );
Font f = getFont();
if ( isSelected ) {
setFont( new Font( f.getName(), Font.PLAIN|Font.ITALIC, f.getSize() ) );
super.setForeground( ( selectedForeground != null) ? selectedForeground : table.getSelectionForeground() );
super.setBackground( ( selectedBackground != null) ? selectedBackground : table.getSelectionBackground() );
}
else {
setFont( new Font( f.getName(), Font.PLAIN, f.getSize() ) );
if ( ((column)>>1)<<1 == column - (row-((row>>1)<<1)) ) {
super.setForeground( ( unselectedForegroundAlt != null) ? unselectedForegroundAlt : table.getForeground() );
super.setBackground( ( unselectedBackgroundAlt != null) ? unselectedBackgroundAlt : table.getBackground() );
}
else {
super.setForeground( ( unselectedForeground != null) ? unselectedForeground : table.getForeground() );
super.setBackground( ( unselectedBackground != null) ? unselectedBackground : table.getBackground() );
}
}
setText( (String)val );
//mise a jour de la base de données automatiquement.
update_Row(column);
return this;
}
} |
Partager