this is a little tricky. what exactly are u trying to do? add an icon based on a certain value in that cell or merely add the same icon to all the cells in that column?
i have a piece that adds a lock icon if the cell is not null.
lemme know what exactly you are looking for and i will post the code.
ok, this is a little involved. you need something to build your table model. i assume you have something called MyTableModel that extends AbstractTableModel
now, heres the code (its all in my main class):
public void setUpTableCells()
{
TableColumn col=null;
col=repairQTable.getColumnModel().getColumn(1);
col.setPreferredWidth(300);
lockRenderer mylockrenderer=new lockRenderer();
col.setCellRenderer(mylockrenderer);
}
class lockRenderer extends JLabel implements TableCellRenderer
{
public lockRenderer()
{
super();
}
public Component getTableCellRendererComponent(JTable table,Object locked,boolean isSelected,boolean hasFocus,int row, int column)
{
JLabel retLabel;
if(locked==null)//locked is a value passed to the function. it holds the value of a certain row,col in my table model
{
retLabel=new JLabel();
retLabel.setToolTipText("");
}
else
{
retLabel=new JLabel("",new ImageIcon("images/lockSmall.gif",""),JLabel.CENTER);
retLabel.setToolTipText("Locked by " + locked);
}
setBorder(BorderFactory.createMatteBorder(2,5,2,5,table.getBackground()));
return retLabel;
}
}
I hope that makes sense. it actually does work for me.