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
| class CustomRenderer extends JLabel implements TableCellRenderer {
ArrayList<Data> list;
final Font normalFont = new Font("SansSerif", Font.PLAIN, 12);
final Font alertFont = new Font("SansSerif", Font.BOLD, 13);
CustomRenderer(ArrayList<Data> list) {
super();
this.list = list;
this.setOpaque(true);
}
@SuppressWarnings("unused")
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
Data data = this.list.getDataAtIndex(row);
Border border = null;
int align = 0;
Color bg = Color.white;
String s = value.toString();
Font font = normalFont;
switch (column) {
case 0:
align = SwingConstants.CENTER;
if (isSelected) {border = BorderFactory.createMatteBorder(2, 2, 2, 0, Color.black);}
break;
case 1:
align = SwingConstants.CENTER;
if (isSelected) {border = BorderFactory.createMatteBorder(2, 0, 2, 0, Color.black);}
break;
case 2:
align = SwingConstants.LEFT;
if (isSelected) {border = BorderFactory.createMatteBorder(2, 0, 2, 0, Color.black);}
if (!data.isProfilPlaned()) {
bg = Color.red;
font = alertFont;
}
break;
case 3:
align = SwingConstants.LEFT;
if (isSelected) {border = BorderFactory.createMatteBorder(2, 0, 2, 2, Color.black);}
if (data.getTime()> 600 ) {
bg = Color.red;
font = alertFont;
} else if (data.getTime()<300) {
bg = Color.white;
} else {
bg = Color.orange;
font = alertFont;
}
break;
}
this.setBorder(border);
this.setText(s);
this.setToolTipText(s);
this.setHorizontalAlignment(align);
this.setFont(font);
this.setForeground(Color.black);
this.setBackground(bg);
return this;
}
} |
Partager