Java 将JTable中的布尔复选框替换为图像图标复选框

Java 将JTable中的布尔复选框替换为图像图标复选框,java,swing,jtable,tablecellrenderer,Java,Swing,Jtable,Tablecellrenderer,嗨,我和他有同样的问题 但我已经部分解决了这一问题: table.getColumnModel().getColumn(i).setCellRenderer(new CustomBooleanCellRenderer()); table.getColumnModel().getColumn(i).setCellEditor(new CustomBooleanCellEditor()); 而且工作。。。但我不能将图标居中。。。我不能自动更新,知道吗?基本上,在渲染器和编辑

嗨,我和他有同样的问题

但我已经部分解决了这一问题:

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

而且工作。。。但我不能将图标居中。。。我不能自动更新,知道吗?

基本上,在渲染器和编辑器中,您需要将
JCheckBox
水平对齐设置为
中心

public class CustomCheckBox extends JCheckBox {

    //...

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

(注意-自定义编辑器和渲染器都使用
CustomCheckBox

我相信我可以为您创建更多(问题);)