Setting selected cell colors
[nobr]Hello
Selected cells in my JTable have white background and foreground color, which is annoying as one cannot see the cellcontent. I use a custom tablecellrenderer, and guess that is part of the reason. Setting the tables setSelectionBackground() does nothing. I suspect that some change in my tablecellrenderer is appropriate, but do not know how to check if the cell being rendered is selected or not. My cellrenderer is below.
import javax.swing.table.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import no.jer.library.toolbox.FMT;
publicclass MyTableCellRendererextends DefaultTableCellRenderer{
//private final Color orig = new Color(255, 255, 255);
privatefinal Color orig = super.getBackground();
private FMT fmt =new FMT();
/** Sets default format from current locale as
* correct way to render a number.
*/
public MyTableCellRenderer(){
super();
}
public MyTableCellRenderer(FMT fmt){
super();
this.fmt = fmt;
}
/** Overrides DefaultTableCellRenderer method.<br>
*/
publicvoid setValue(Object value){
//logg.append(orig.toString()+"\n");
if ((value !=null) && (valueinstanceof Number)){
if(valueinstanceof Double){
Double val = (Double) value;
if(val.isNaN() || val.doubleValue()<=this.fmt.getNanLimit()){
this.setBackground(Color.RED);
}else{
//this.setBackground(super.getBackground());
this.setBackground(orig);
}
this.setHorizontalAlignment(JLabel.RIGHT);
value = fmt.fdf(val).trim();
}elseif(valueinstanceof Integer){
this.setHorizontalAlignment(JLabel.RIGHT);
this.setBackground(orig);
}
}elseif((value !=null) && (valueinstanceof String)){
this.setBackground(orig);
this.setHorizontalAlignment(JLabel.LEFT);
}elseif((value!=null) && (valueinstanceof Date)){
this.setBackground(orig);
value = fmt.f((Date)value).trim();
this.setHorizontalAlignment(JLabel.LEFT);
}elseif((value !=null) && (valueinstanceof GregorianCalendar)){
GregorianCalendar greg = (GregorianCalendar) value;
this.setBackground(orig);
this.setHorizontalAlignment(JLabel.LEFT);
value = fmt.f(greg).trim();
greg =null;
}else{
this.setBackground(orig);
this.setHorizontalAlignment(JLabel.LEFT);
value = fmt.f(value);
}
super.setValue(value);
}
public FMT getFmt(){
return fmt;
}
publicvoid setFmt(FMT fmt){
this.fmt = fmt;
}
}//END
Regards
Fluid[/nobr]

