0

I am new to Java. I have created a JTable. This is how addRow method works when I try to add a row to the table.

private void addTableRow(String type, String name, String rank, String notes, String location, Color color)
    {
        boolean isExport = isExportEnable();

        tableModel.addRow(new Object[]
        {
            type,
            name,
            rank,
            notes,
            location,
            isExport
        });
    }

When adding the row I want to fill a different color for the column index 6. I created a custom table cell renderer.

public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int col) 
{
    getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    setBackground(Color.BLACK);
    return this;
}

But I have no idea:

  1. How should I call this method when adding a row? I tried to call it after isExport value but there, it shows errors for method parameters.
  2. What values should I use for parameters in getTableCellRendererComponent() method?
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ann
  • 21
  • 6
  • You're not supposed to call that method, ever. The JTable calls it every time it needs to render a cell. The first instruction should be **super.**getTable... – JB Nizet Jul 11 '18 at 17:09
  • Possible duplicate of [JTable Cell Renderer](https://stackoverflow.com/questions/6644922/jtable-cell-renderer) – Marcos Vasconcelos Jul 11 '18 at 17:10

0 Answers0