Question

Hi I have the same problem that him.

Trying to replace boolean check-box in a JTable with an image-icon checkbox

but I have partly solve doing this:

table.getColumnModel().getColumn(i).setCellRenderer(new CustomBooleanCellRenderer());           
table.getColumnModel().getColumn(i).setCellEditor(new CustomBooleanCellEditor());

and works... but I cant center the icon... and I cant update automatically, any idea?

Was it helpful?

Solution

Basically, in the renderer and editor, you need to set the JCheckBox's horizontalAlignment to CENTER

public class CustomCheckBox extends JCheckBox {

    //...

    public CustomCheckBox() {
        //...
        setHorizontalAlignment(CENTER);
    }

(nb- The custom editor and renderer both use the CustomCheckBox)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top