问题
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:
- 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. - What values should I use for parameters in
getTableCellRendererComponent()
method?
来源:https://stackoverflow.com/questions/51290916/use-custom-tablecellrenderer-in-a-jtable