private void handleMousePress ( MouseEvent e ) { int row = getRowForLocation ( e . getX ( ) , e . getY ( ) ) ; TreePath path = getPathForLocation ( e . getX ( ) , e . getY ( ) ) ; if ( path == null ) { return ; } TreeCellRenderer cellRenderer = getCellRenderer ( ) ; TreeNode node = ( TreeNode ) path . getLastPathComponent ( ) ; Component cellRendererComponent = cellRenderer . getTreeCellRendererComponent ( CheckBoxTree . this , null , true , true , node . isLeaf ( ) , row , true ) ; Rectangle bounds = getRowBounds ( row ) ; Point localPoint = new Point ( ) ; localPoint . x = e . getX ( ) - bounds . x ; localPoint . y = e . getY ( ) - bounds . y ; Container container = ( Container ) cellRendererComponent ; Component clickedComponent = null ; for ( Component component : container . getComponents ( ) ) { Rectangle b = component . getBounds ( ) ; if ( b . contains ( localPoint ) ) { clickedComponent = component ; } } if ( clickedComponent != null ) { if ( clickedComponent instanceof JCheckBox ) { toggleSelection ( path ) ; repaint ( ) ; } } }
Handle a mouse press and possibly toggle the selection state