class MyTableCellRenderer implements TableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
//根据特定的单元格设置不同的Renderer,假如你要在第2行第3列显示图标
if(row == 1 && column == 2) {
ImageIcon icon = new ImageIcon("icon的位置");
JLabel label = new JLabel(icon);
label.setOpaque(false);
return label;
} else {
......
......
}
}
然后把这个Renderer设置到第一列上
TableCellRenderer myRenderer = new MyTableCellRenderer();
table.getColumnModel.getColumn(2).setCellRenderer(myRenderer);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
//根据特定的单元格设置不同的Renderer,假如你要在第2行第3列显示图标
if(row == 1 && column == 2) {
ImageIcon icon = new ImageIcon("icon的位置");
JLabel label = new JLabel(icon);
label.setOpaque(false);
return label;
} else {
......
......
}
}
然后把这个Renderer设置到第一列上
TableCellRenderer myRenderer = new MyTableCellRenderer();
table.getColumnModel.getColumn(2).setCellRenderer(myRenderer);