boolean checkbox swing

Solutions on MaxInterview for boolean checkbox swing by the best coders in the world

showing results for - "boolean checkbox swing"
Marta
22 Nov 2017
1boolean isSelected = jCheckBox.isSelected();
2
3if(isSelected ){
4   jCheckBox.setSelected(false);
5} else {
6   jCheckBox.setSelected(true);
7}
Arthur
16 Apr 2020
1static class BooleanRenderer extends JCheckBox implements TableCellRenderer, UIResource
2{
3    private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
4
5    public BooleanRenderer() {
6        super();
7        setHorizontalAlignment(JLabel.CENTER);
8        setBorderPainted(true);
9    }
10
11    public Component getTableCellRendererComponent(JTable table, Object value,
12                                                   boolean isSelected, boolean hasFocus, int row, int column) {
13        if (isSelected) {
14            setForeground(table.getSelectionForeground());
15            super.setBackground(table.getSelectionBackground());
16        }
17        else {
18            setForeground(table.getForeground());
19            setBackground(table.getBackground());
20        }
21        setSelected((value != null && ((Boolean)value).booleanValue()));
22
23        if (hasFocus) {
24            setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
25        } else {
26            setBorder(noFocusBorder);
27        }
28
29        return this;
30    }
31}