You need to redefine the cellrenderer:
static class MyBooleanCellRenderer extends JCheckBox implements TableCellRenderer
{
private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
public MyBooleanCellRenderer () {
super();
setHorizontalAlignment(JLabel.CENTER);
setBorderPainted(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
}
else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}
setSelected((value != null && ((Boolean)value).booleanValue()));
if (hasFocus) {
setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
} else {
setBorder(noFocusBorder);
}
//si votre condition retourner un JLabel vide, sinon retourner this (JCheckbox)
if (
return new JLabel();
return this;
}
}
and add this cellrenderer to the required column
TableColumn tcol = tableDestock.getColumnModel().getColumn(0);
tcol.setCellRenderer(new MyBooleanCellRenderer ());
No comments:
Post a Comment