I'm implementing TableCellRenderer to make a visible diference if the last value is or not certain value.
So, the code of these implementation is:
TableColumnModel tcm = table.getColumnModel();
TableColumn col = tcm.getColumn(column);
JLabel cellComponent = new JLabel();
if (value != null)
{
cellComponent.setText( String.valueOf( value ) );
}else
cellComponent.setText( "-" );
String colName = (String) col.getHeaderValue();
if (colName.startsWith("Vigencia") && !cellComponent.getText().equals("-"))
{
long dias = Long.valueOf(cellComponent.getText());
if (dias <0)
{
dias = dias -(dias*2); //Le resto (dias x 2) para sacarle el negativo...
cellComponent.setText( String.valueOf(dias) );
cellComponent.setBorder( BorderFactory.createLineBorder(Color.RED));
}
}
to populate my table I have a Class that extends from JTable and have this method to populate the table:
public void setData(LinkedList<T> list)
{
if (list.size() == 0)
{
cleanTableData();
return;
}
int index = 0;
Object[][] o = new Object[list.size()][_columnNames.length];
for (T obj : list)
{
Object[] data = obj.toStringReporte();
o[index++] = data;
}
_tableModel = new DefaultTableModel( o, _columnNames );
setModel(_tableModel);
setColumnWidths();
}
toStringReporte method is this one:
public Object[] toStringReporte()
{
String planName = "-";
if (getPlanID() != null)
{
Plan plan = Adapter.getInstance().getElement(getPlanID(), new Plan());
planName = plan.getNombre();
}
return new Object[]{getID(),
getNombre(),
getApellido(),
getDni(),
(getEstado().equals("A") ? "Activo" : "Inactivo"),
(getSexo().equals("M") ? "Masculino" : "Femenino"),
(getFichaMedica() != null ? new SimpleDateFormat(Defines.DATE_FORMAT).format(new Date(getFichaMedica())) : "-"),
planName,
(getFechaVencimiento() != null ? SGGDateUtils.diferenceInDaysBetweenTwoDatesMS(getFechaVencimiento(), new Date().getTime()) : "-")};
}
My problem is that (as Class name tells) the only change is cell border. I want to change entire row border.
Some body know how to change the border of entire row?
Table Row Rendering shows how you might render a row level border.