I successful add checkbox into JTable's column. but I want to use my custom checkbox, i modified BooleanRender to extend my custom checkbox , and it works.the problem is when I selected the checkbox it will show default jCheckbox design at moment and show my coustom checkbox, it also happen when i unselected the checkbox. here is the question I asked before
class BooleanRenderer extends TriCheckBox implements TableCellRenderer, UIResource {
private static final long serialVersionUID = 1L;
private final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
BooleanRenderer() {
super();
setHorizontalAlignment(JLabel.CENTER);
setBorderPainted(true);
}
@Override
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);
}
return this;
}
}
public class TriCheckBox extends JCheckBox {
public static ImageIcon icon =new ImageIcon("src/checkbox_off.png");
public static ImageIcon smallIcon = new ImageIcon(icon.getImage().getScaledInstance (12, -1, Image.SCALE_SMOOTH));
public static ImageIcon iconDark =new ImageIcon("src/logo.png");
public static ImageIcon smallIconDark = new ImageIcon(iconDark.getImage().getScaledInstance (12, -1, Image.SCALE_SMOOTH));
public static ImageIcon iconBrown =new ImageIcon("src/checkbox_on.png");
public static ImageIcon smallIconBrown = new ImageIcon(iconBrown.getImage().getScaledInstance (12, -1, Image.SCALE_SMOOTH));
private boolean indeterminate;
@Override
public void paint(Graphics g) {
if (isSelected()) {
indeterminate = false;
}
if(indeterminate){
setIcon(smallIconDark);
}else if(isSelected()){
setIcon(smallIconBrown);
}else{
setIcon(smallIcon);
}
super.paint(g);
}
public boolean isIndetermainate() {
return indeterminate;
}
public void setIndetermainate(boolean indetermainate) {
this.indeterminate = indetermainate;
if (indetermainate) {
setSelected(false);
repaint();
}
}
}