سؤال

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?

هل كانت مفيدة؟

المحلول

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)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top