“Kotak centang boolean ayunan” Kode Jawaban

Kotak centang boolean ayunan

boolean isSelected = jCheckBox.isSelected();

if(isSelected ){
   jCheckBox.setSelected(false);
} else {
   jCheckBox.setSelected(true);
}
Breakable Barracuda

Kotak centang boolean ayunan

static class BooleanRenderer extends JCheckBox implements TableCellRenderer, UIResource
{
    private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);

    public BooleanRenderer() {
        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);
        }

        return this;
    }
}
Breakable Barracuda

Jawaban yang mirip dengan “Kotak centang boolean ayunan”

Pertanyaan yang mirip dengan “Kotak centang boolean ayunan”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya