package de.wwwu.awolf.view.custom; import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; import java.awt.*; /** * Source: http://esus.com/creating-a-jtable-with-a-different-background-color-per-column/ *

* Applied background and foreground color to single column of a JTable * in order to distinguish it apart from other columns. */ public class ColorColumnRenderer extends DefaultTableCellRenderer { Color bkgndColor, fgndColor; public ColorColumnRenderer(Color bkgnd, Color foregnd) { super(); bkgndColor = bkgnd; fgndColor = foregnd; } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column); cell.setBackground(bkgndColor); cell.setForeground(fgndColor); cell.setFont(new Font("SansSerif", Font.BOLD, 12)); this.setHorizontalAlignment(JLabel.CENTER); return cell; } }