I have changed the cell render in JTable to show image instead of text using the following code:
base_table.getColumnModel().getColumn(3).setCel
below is the correct image renderer class.
class SimpleCellRenderer extends DefaultTableCellRenderer{
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
column);
((JLabel)cell).setIcon((Icon)value);
((JLabel)cell).setText("");
((JLabel)cell).setHorizontalAlignment(JLabel.CENTER);
if (isSelected) {
cell.setBackground(Color.white);
} else {
cell.setBackground(null);
}
//((AbstractTableModel)table.getModel()).fireTableCellUpdated(row,column);
return cell;
}
}
below is the method from where everything gets filled automtically. private void formWindowOpened(java.awt.event.WindowEvent evt)
{
// TODO add your handling code here:
fillIcon();
}
public void fillIcon() {
int i,j,rowValue,colValue;
int cols= student.getColumnCount();
int rows=student.getRowCount();
for(i =0 ;i