fix checkbox togging with mouse (do not access `checkbox.getX()` as these components...
[idea/community.git] / platform / platform-api / src / com / intellij / ui / CheckBoxList.java
index 37ff932fce491c27b5b02aaa15da2ea330050b30..d600de0170471444975c2c73567478050e7983ed 100644 (file)
@@ -42,7 +42,8 @@ public class CheckBoxList<T> extends JBList {
     super();
     //noinspection unchecked
     setModel(dataModel);
-    setCellRenderer(new CellRenderer());
+    final CellRenderer cellRenderer = new CellRenderer();
+    setCellRenderer(cellRenderer);
     setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     setBorder(BorderFactory.createEtchedBorder());
     addKeyListener(new KeyAdapter() {
@@ -75,7 +76,8 @@ public class CheckBoxList<T> extends JBList {
             catch (ClassCastException c) {
               iconArea = DEFAULT_CHECK_BOX_WIDTH;
             }
-            if (e.getX() < iconArea + checkbox.getX()) {
+            int checkboxX = e.getX() - cellRenderer.getLeftBorderThickness();
+            if (checkboxX >= 0 && checkboxX < iconArea) {
               setSelected(checkbox, index);
               return true;
             }
@@ -180,11 +182,13 @@ public class CheckBoxList<T> extends JBList {
   private class CellRenderer implements ListCellRenderer {
     private final Border mySelectedBorder;
     private final Border myBorder;
+    private final int myLeftBorderThickness;
 
     private CellRenderer() {
       mySelectedBorder = UIManager.getBorder("List.focusCellHighlightBorder");
       final Insets borderInsets = mySelectedBorder.getBorderInsets(new JCheckBox());
       myBorder = new EmptyBorder(borderInsets);
+      myLeftBorderThickness = borderInsets.left;
     }
 
     @Override
@@ -239,6 +243,10 @@ public class CheckBoxList<T> extends JBList {
 
       return rootComponent;
     }
+
+    private int getLeftBorderThickness() {
+      return myLeftBorderThickness;
+    }
   }
 
   @Nullable