codice:
public class MyRenderer extends DefaultTableCellRenderer {
//private Font font = new Font("Courier", Font.BOLD, 12);
public MyRenderer()
{
super();
this.setEnabled(true);
this.setFocusable(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
if(isSelected == true)
{
setForeground(Color.GREEN);
}
return super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
}
}
codice:
public class MyTable extends JTable {
private TableCellRenderer customRenderer = new MyRenderer();
private int targetRow;
public int irowSel = -1;
public boolean bFound = false;
private static final int DEFAULT_COLUMN_PADDING = 5;
public MyTable(int targetRow) {
this.targetRow = targetRow;
this.setDefaultRenderer(Color.class,customRenderer);
this.setCellSelectionEnabled(true);
this.setColumnSelectionAllowed(false);
this.setRowSelectionAllowed(true);
//this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.setFocusable(true);
autoResizeTable ( this, true, 10);
}
public TableCellRenderer getCellRenderer(int r, int c) {
if(irowSel == r)
{
return customRenderer;
}
else
{
return super.getCellRenderer(r, c);
} }
Il mio problema è evidenziato in arancione....Cioè: le righe vengono colorate in modo esatto. Ma poichè allo show del frame lui ripassa in getCellRenderer "iRowsSel" è l'ultimo che ha impostato. Quindi vedo colorata solo l'ultima trovata....
Grazie