/* ColoredTableCellRenderer.java */import java.awt.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.table.*;public class ColoredTableCellRendererimplements TableCellRenderer{ private Color lightBlue = new Color(160, 160, 255); private Color darkBlue = new Color( 64, 64, 128); Border a = BorderFactory.createLineBorder(Color.green, 3); Border b = BorderFactory.createEmptyBorder(1, 1, 1, 1); JLabel label = new JLabel(); public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) { //Label erzeugen label.setText((String)value); label.setOpaque(true); label.setBorder(b); label.setFont(table.getFont()); label.setForeground(table.getForeground()); label.setBackground(table.getBackground()); if (hasFocus) { label.setBackground(darkBlue); label.setForeground(Color.white); label.setBorder(a); } else if (isSelected) { label.setBackground(lightBlue); } else { //Angezeigte Spalte in Modellspalte umwandeln column = table.convertColumnIndexToModel(column); if (column == 1) { if (row < 11) { label.setBackground(Color.red); } else if (row < 21) { label.setBackground(Color.orange); } else { label.setBackground(Color.yellow); } } } return label; }}// Renderer wird der Tabelle zugewiesensuchTab.setDefaultRenderer(Object.class,new ColoredTableCellRenderer());