Question

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?

Was it helpful?

Solution

Table Row Rendering shows how you might render a row level border.

OTHER TIPS

You cannot do this with just a TableCellRenderer, as it works independently on each cell.

If you want to apply an effect to an entire row, you will likely need to override the prepareRenderer method of JTable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top