Use custom TablecellRenderer in a JTable

こ雲淡風輕ζ 提交于 2019-12-20 05:38:10

问题


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?

来源:https://stackoverflow.com/questions/51290916/use-custom-tablecellrenderer-in-a-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!