2020-03-21 00:37:09 +00:00
|
|
|
package de.wwwu.awolf.view.custom;
|
2017-09-10 15:45:47 +00:00
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import javax.swing.table.DefaultTableCellRenderer;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Source: <url> http://esus.com/creating-a-jtable-with-a-different-background-color-per-column/ </url>
|
|
|
|
* <p>
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|