Hope it is Done. Look
table.setDefaultRenderer(Severity.class, renderer );
//renderer means our SeverityRenderer.
Next what to do in the comment place.
Severity.java
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
public class Severity {
private final static Map VALUES = new HashMap();
public final static Severity MAJOR = new Severity("Major");
public final static Severity MINOR = new Severity("Minor");
public final static Severity INFORMATION = new Severity("Information");
public final static Severity CRITICAL = new Severity("Critical");
public final static Severity WARNING = new Severity("Warning");
private final
String description;
private Severity(String description){
this.description = description;
VALUES.put( description, this );
}
public String getDescription() {
return this.description;
}
public String toString() {
return getDescription();
}
public boolean equals( Object obj ) {
if( ! (obj instanceof Severity ) ) {
return false;
}
Severity s = ( Severity ) obj;
return s.getDescription().equals( getDescription() );
}
public int hashCode() {
return getDescription().hashCode();
}
public static Severity getSeverity( String description ) {
return ( Severity ) VALUES.get( description );
}
}
SeverityRenderer.java
import java.awt.Component;
//import java.awt.Color;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
//import javax.swing.table.TableCellRenderer;
//import javax.swing.table.TableCellEditor;
public class SeverityRenderer extends DefaultTableCellRenderer {
public SeverityRenderer(){
}
public Component getTableCellRendererComponent(
JTable table,Object value,boolean isSelected,boolean hasFocus,
int row,int column){
Severity severity = ( Severity ) value;
Component cell = super.getTableCellRendererComponent(
table,severity.getDescription(),isSelected,hasFocus,
row, column);
// Decide what colour to paint the cell
// Colour the cell
return cell;
}
}