I am trying to add an icon to a specific JTable column by specifying my own rendering of table cells as shown below ( based on parts of this tutorial ):
public class MyTableCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if(column == MyTableModel.IMAGE_COLUMN){ String status = (String)value; Icon icon = StatusImageUtil.getStatusIcon(status); if(icon == null){ label.setText(status); }else{ label.setIcon(icon); } } return label; } }
The above code works, but:
- All cells have an icon instead of a specific one, which I want to indicate in the if statement
- Cell MyTableModel.IMAGE_COLUMN, which should only have a text icon.
Thank you in advance
source share