Add Image in JTable without using renderer
-
27-04-2021 - |
Question
I need to add image in Jtable cell without using TableCellRenderer.If i Use the following code means it display the name (string) in that particular cell instead of image.how to do this?.
ImageIcon Icon= new ImageIcon("Blank.gif");
table.setValueAt(Icon,1,0);
using renderer
class FRM_FLXD_ICON_ASSGN extends DefaultTableCellRenderer {
ImageIcon Icon;
public Component getTableCellRendererComponent(
JTable table, Object value, boolean selected, boolean focus,
int row, int col) {
if(selected == true){
Icon=new ImageIcon(getClass().getResource("Pointer.gif"));
}
else{
Icon=new ImageIcon(getClass().getResource("Blank.gif"));
}
this.setIcon(Icon);
return this;
}
}
Solution
JTable know Icon/ImageIcon Object, then you can add Icon/ImageIcon
directly to the JTable
, example
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow