I have a JTable and I want when selecting a row in the table it will be colored blue and have a green border marked around the row. I was able to make the color blue but can not make a green border marked around the row . I have attached a picture -This is what it should be.
Thanks in advance After editing: I add to my code :
JTable jTable1 = new JTable( model )
{
// Returning the Class of each column will allow different
// renderers to be used based on Class
public Class getColumnClass(int column)
{
return columns[column];
}
@Override
public boolean isCellEditable(int row, int column) {
//all cells false
return false;
}
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
Component c = super.prepareRenderer(renderer, row, col);
JComponent jc = (JComponent)c;
if (isRowSelected(row)){
int top = (row > 0 && isRowSelected(row-1))?1:2;
int left = col == 0?2:0;
int bottom = (row < getRowCount()-1 && isRowSelected(row + 1))?1:2;
int right = col == getColumnCount()-1?2:0;
jc.setBorder(BorderFactory.createMatteBorder(top, left, bottom, right, new Color(210,236,204)));
jc.setForeground(new Color(164, 164, 172));
}
else{
jc.setBorder(null);
}
int selCol = -2;
int selRow = jTable1.getSelectedRow();
if ( selCol != -1 && selRow != -1 ){
if ( row == selRow || col == selCol){
c.setBackground(new Color(249,250,254));
}else
c.setBackground(Color.WHITE);
}
return c;
}
};
And I almost got What I wanted, but if you look closely the color missing between each cell. What should I do?
This is what I have now