2
It may sound silly, but I can’t find the method to remove the color from the selection when the mouse clicks on the line. I have a table with red and blue lines, blue colors are lines that mean an action and red other actions. However, when I select the line, the color is superimposed by the opaque blue of Jtable’s standard selection, of course when clicking another line the defined color of the clicked line goes back to normal. Anyway, my question is, how to remove this opaque blue pattern from Jtable that signals line selection?
Below is my code, all conditions work except "isSelect", where should leave the line with the color that already exists, and do not overlap with the selection color.
Code
package commons;
import java.awt.Color;
import java.awt.Component;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import model.SdkDynRellation;
import view.ViewInit;
import com.sun.tools.xjc.generator.bean.field.IsSetFieldRenderer;
public class ColorCellRenderer extends DefaultTableCellRenderer {
private List<String> list;
public ColorCellRenderer() {
super();
}
public ColorCellRenderer(List<String> list2) {
list = list2;
setOpaque(true);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
final JLabel cellComponent = (JLabel) super
.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
Object val = table.getValueAt(row, 0);
Object check = table.getValueAt(row, 1);
if (!AuxClass.isBegin) {
if (list.contains(val.toString())
&& check.toString().equals("true")) {
cellComponent.setForeground(Color.WHITE);
cellComponent.setBackground(Color.BLUE);
} else {
if (check.toString().equals("true") && new SdkDynRellation().getIndexes().contains(val))
{
cellComponent.setBackground(Color.RED);
cellComponent.setForeground(Color.WHITE);
}
else
{
if (check.toString().equals("true"))
{
cellComponent.setBackground(Color.BLUE);
cellComponent.setForeground(Color.WHITE);
}
else
{
cellComponent.setBackground(Color.WHITE);
cellComponent.setForeground(Color.black);
}
}
}
if (isSelected)
{
cellComponent.setBackground(getBackground());
}
} else {
if (list.contains(val.toString())
&& check.toString().equals("true")) {
cellComponent.setForeground(Color.WHITE);
cellComponent.setBackground(Color.RED);
} else {
cellComponent.setBackground(Color.WHITE);
cellComponent.setForeground(Color.black);
}
}
return super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
}
}
In the redenderer execute
setOpaque(true)
. Also look at the method setSelectionBackground.– stderr
@Qmechanic73 hasn’t solved my problem yet, I edited the question and put my code.
– Maicon Funke