Checkbox in some cells but not all, in a particular column - JTable

前端 未结 3 1892
悲哀的现实
悲哀的现实 2021-01-15 02:55

This may be a vague query, so please pardon me.

Customized JTable (I\'ve modified the query and will discuss based on the SSCCE provided). I\'ve to create a JTable t

3条回答
  •  离开以前
    2021-01-15 03:20

    Override the getCellRenderer() method to return an appropriate renderer. Something like:

    @Override
    public TableCellRenderer getCellRenderer(int row, int column)
    {
        int modelColumn = convertColumnIndexToView(column);
    
        if (modelColumn == 0 && getValueAt(row, column).equals(""))
            return getDefaultRenderer(String.class);
        else
            return super.getCellRenderer(row, column);
    }
    

    You would also need to change the data in the model:

    {"", "File", ""},
    

    Finally you would also override the isCellEditable() method to make the empty cell non editable.

    Then you can just use the default Boolean renderer/editor for the other rows in the column.

提交回复
热议问题