package example;
// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.Objects;
import java.util.Optional;
import javax.swing.*;
import javax.swing.table.*;

public final class MainPanel extends JPanel {
    private final String[] columnNames = {"String", "Boolean"};
    private final Object[][] data = {
        {"AAA", true}, {"bbb", false},
        {"CCC", true}, {"ddd", false},
        {"EEE", true}, {"fff", false},
    };
    private final TableModel model = new DefaultTableModel(data, columnNames) {
        @Override public Class<?> getColumnClass(int column) {
            return column == 1 ? Boolean.class : super.getColumnClass(column);
        }
        @Override public boolean isCellEditable(int row, int column) {
            return column == 1;
        }
    };
    private final JTable table = new JTable(model) {
        @Override public void updateUI() {
            // setDefaultRenderer(Boolean.class, null);
            setDefaultEditor(Boolean.class, null);
            super.updateUI();
            // setDefaultRenderer(Boolean.class, new CheckBoxPanelRenderer());
            setDefaultEditor(Boolean.class, new CheckBoxPanelEditor());
        }
    };
    private MainPanel() {
        super(new BorderLayout());
        table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
        table.setRowHeight(24);
        table.setRowSelectionAllowed(true);
        table.setShowVerticalLines(false);
        table.setIntercellSpacing(new Dimension(0, 1));
        table.setFocusable(false);
        add(new JScrollPane(table));
        setPreferredSize(new Dimension(320, 240));
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGui();
            }
        });
    }
    public static void createAndShowGui() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class CheckBoxPanelEditor extends AbstractCellEditor implements TableCellEditor {
    protected final Container renderer = new JPanel(new GridBagLayout()) {
        protected transient MouseListener listener;
        @Override public void updateUI() {
            removeMouseListener(listener);
            super.updateUI();
            setBorder(UIManager.getBorder("Table.noFocusBorder"));
            listener = new MouseAdapter() {
                @Override public void mousePressed(MouseEvent e) {
                    fireEditingStopped();
                }
            };
            addMouseListener(listener);
        }
    };
    protected final JCheckBox checkBox = new JCheckBox() {
        protected transient Handler handler;
        @Override public void updateUI() {
            removeActionListener(handler);
            removeMouseListener(handler);
            super.updateUI();
            setOpaque(false);
            setFocusable(false);
            setRolloverEnabled(false);
            handler = new Handler();
            addActionListener(handler);
            addMouseListener(handler);
        }
    };
    @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        checkBox.setSelected(Objects.equals(value, Boolean.TRUE));
        // renderer.setBackground(table.getSelectionBackground());
        // renderer.removeAll();
        renderer.add(checkBox);
        return renderer;
    }
    @Override public Object getCellEditorValue() {
        return checkBox.isSelected();
    }
    private class Handler extends MouseAdapter implements ActionListener {
        @Override public void actionPerformed(ActionEvent e) {
            fireEditingStopped();
        }
        @Override public void mousePressed(MouseEvent e) {
            Container c = SwingUtilities.getAncestorOfClass(JTable.class, e.getComponent());
            if (c instanceof JTable) {
                JTable table = (JTable) c;
                if (checkBox.getModel().isPressed() && table.isRowSelected(table.getEditingRow()) && e.isControlDown()) {
                    renderer.setBackground(table.getBackground());
                } else {
                    renderer.setBackground(table.getSelectionBackground());
                }
            }
        }
        @Override public void mouseExited(MouseEvent e) {
            Class<JTable> clz = JTable.class;
            Optional.ofNullable(SwingUtilities.getAncestorOfClass(clz, e.getComponent()))
                .filter(clz::isInstance).map(clz::cast)
                .filter(table -> table.isEditing() && !table.getCellEditor().stopCellEditing())
                .ifPresent(table -> table.getCellEditor().cancelCellEditing());
            // Container c = SwingUtilities.getAncestorOfClass(JTable.class, e.getComponent());
            // if (c instanceof JTable) {
            //     JTable table = (JTable) c;
            //     if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
            //         table.getCellEditor().cancelCellEditing();
            //     }
            // }
        }
    }
}
// class CheckBoxPanelEditor extends AbstractCellEditor implements TableCellEditor {
//     private final JPanel p = new JPanel(new GridBagLayout());
//     private final JCheckBox checkBox = new JCheckBox();
//     protected CheckBoxPanelEditor() {
//         super();
//         checkBox.setOpaque(false);
//         checkBox.setFocusable(false);
//         checkBox.setRolloverEnabled(false);
//         checkBox.addActionListener(e -> fireEditingStopped());
//         p.add(checkBox);
//         p.setBorder(UIManager.getBorder("Table.noFocusBorder"));
//     }
//     @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
//         checkBox.setSelected(Objects.equals(value, Boolean.TRUE));
//         p.setBackground(table.getSelectionBackground());
//         return p;
//     }
//     @Override public Object getCellEditorValue() {
//         return checkBox.isSelected();
//     }
// }
// class CheckBoxPanelRenderer implements TableCellRenderer {
//     private final JPanel p = new JPanel(new GridBagLayout());
//     private final JCheckBox checkBox = new JCheckBox();
//     protected CheckBoxPanelRenderer() {
//         checkBox.setOpaque(false);
//         checkBox.setFocusable(false);
//         checkBox.setRolloverEnabled(false);
//         p.add(checkBox);
//         p.setBorder(UIManager.getBorder("Table.noFocusBorder"));
//     }
//     @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
//         checkBox.setSelected(Objects.equals(value, Boolean.TRUE));
//         p.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
//         return p;
//     }
// }

@@ -5126,78 +5126,25 @@
 ter(
-t
+JT
 able
- -%3E table.isEditing() && !table.getCellEditor().stopCell
+::is
 Editing
-()
 )%0A  
@@ -5172,90 +5172,66 @@
 ent(
-t
+JT
 able
- -%3E table.getCellEditor().cancelCellEditing());%0A            // Container c = 
+::removeEditor);%0A            // Optional.ofNullable(
 Swin
@@ -5256,36 +5256,27 @@
 storOfClass(
-JTable.class
+clz
 , e.getCompo
@@ -5274,33 +5274,33 @@
 .getComponent())
-;
+)
 %0A            // 
@@ -5303,104 +5303,88 @@
  // 
-if (c instanceof JTable) %7B%0A            //     JTable table = (JTable) c;%0A            //     if (
+    .filter(clz::isInstance).map(clz::cast)%0A            //     .filter(table -%3E 
 tabl
@@ -5441,18 +5441,16 @@
 iting())
- %7B
 %0A       
@@ -5457,27 +5457,43 @@
      //     
-   
+.ifPresent(table -%3E
  table.getCe
@@ -5526,47 +5526,10 @@
 ng()
+)
 ;
-%0A            //     %7D%0A            // %7D
 %0A   

use JTable#removeEditor() instead of JTable#getCellEditor().stopCellEditing()