public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
public boolean inCheckBoxHitRegion(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return false; } CategoryNode node = (CategoryNode) path.getLastPathComponent(); boolean rv = false; if (true) { // offset and lastRow DefaultTreeCellEditor // protected members Rectangle bounds = tree.getRowBounds(lastRow); Dimension checkBoxOffset = renderer.getCheckBoxOffset(); bounds.translate(offset + checkBoxOffset.width, checkBoxOffset.height); rv = bounds.contains(e.getPoint()); } return true; }
// If you are interested in detecting either double-click events or when a user clicks on a node, regardless of whether or not it was selected, we recommend you do the following: final JTree tree = ...; MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = tree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if(selRow != -1) { if(e.getClickCount() == 1) { mySingleClick(selRow, selPath); } else if(e.getClickCount() == 2) { myDoubleClick(selRow, selPath); } } } }; tree.addMouseListener(ml);
@Override public void mouseClicked(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); int nActiveTreebanks = getActiveTreebanks().size(); //Tdiff boolean canActivate = (! TregexGUI.getInstance().isTdiffEnabled() || nActiveTreebanks < TregexGUI.MAX_TDIFF_TREEBANKS); if(path != null) { FileTreeNode node = (FileTreeNode) path.getLastPathComponent(); if(canActivate || node.isActive()) node.setActive(!node.isActive()); } } });
@Override public void mousePressed(MouseEvent event) { boolean isClickCountMatches = (event.getClickCount() == 1 && luytenPrefs.isSingleClickOpenEnabled()) || (event.getClickCount() == 2 && !luytenPrefs.isSingleClickOpenEnabled()); if (!isClickCountMatches) return; if (!SwingUtilities.isLeftMouseButton(event)) return; final TreePath trp = tree.getPathForLocation(event.getX(), event.getY()); if (trp == null) return; Object lastPathComponent = trp.getLastPathComponent(); boolean isLeaf = (lastPathComponent instanceof TreeNode && ((TreeNode) lastPathComponent).isLeaf()); if (!isLeaf) return; new Thread() { public void run() { openEntryByTreePath(trp); } }.start(); } }
@Override public void mouseClicked(MouseEvent me) { TreePath path = tree.getPathForLocation(me.getX(), me.getY()); if (path == null) { return; } if (me.getX() > tree.getPathBounds(path).x + hotspot) { return; } boolean selected = selectionModel.isPathSelected(path, true); selectionModel.removeTreeSelectionListener(this); try { if (selected) { selectionModel.removeSelectionPath(path); } else { selectionModel.addSelectionPath(path); } } finally { selectionModel.addTreeSelectionListener(this); treetable.repaint(); } }
TreePath tp = selfPointer.getPathForLocation(arg0.getX(), arg0.getY()); if (tp == null) { return;
@Override public void mouseClicked(final MouseEvent e) { if (!scrollToSource && e.getClickCount() < 2) { return; } final TreePath treePath = resultsTree.getPathForLocation( e.getX(), e.getY()); if (treePath != null) { scrollToError(treePath); } }
public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
/** * Fix compatibility issue with right click on Linux. * @param e Mouse event */ private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } DefaultMutableTreeNode currentTableNode = (DefaultMutableTreeNode) path.getLastPathComponent(); if (currentTableNode.getUserObject() instanceof AbstractNodeModel) { AbstractNodeModel currentTableModel = (AbstractNodeModel) currentTableNode.getUserObject(); if (currentTableModel.isPopupDisplayable()) { currentTableModel.showPopup(currentTableNode, path, e); } } } }
@Override public void mousePressed(MouseEvent e) { int selRow = ManagerDatabase.this.tree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = ManagerDatabase.this.tree.getPathForLocation(e.getX(), e.getY()); if (selRow != -1 && e.getClickCount() == 2) { if (ManagerDatabase.this.tree.isExpanded(selPath)) { ManagerDatabase.this.tree.collapsePath(selPath); } else { ManagerDatabase.this.tree.expandPath(selPath); } } }
final JTree tree = ...; MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = tree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if(selRow != -1) { if(e.getClickCount() == 1) { mySingleClick(selRow, selPath); } else if(e.getClickCount() == 2) { myDoubleClick(selRow, selPath); } } } }; tree.addMouseListener(ml);
public static void main ( String[] args ) { JFrame frame = new JFrame (); final JTree tree = new JTree (); tree.addMouseListener ( new MouseAdapter () { public void mousePressed ( MouseEvent e ) { if ( SwingUtilities.isRightMouseButton ( e ) ) { TreePath path = tree.getPathForLocation ( e.getX (), e.getY () ); Rectangle pathBounds = tree.getUI ().getPathBounds ( tree, path ); if ( pathBounds != null && pathBounds.contains ( e.getX (), e.getY () ) ) { JPopupMenu menu = new JPopupMenu (); menu.add ( new JMenuItem ( "Test" ) ); menu.show ( tree, pathBounds.x, pathBounds.y + pathBounds.height ); } } } } ); frame.add ( tree ); frame.pack (); frame.setLocationRelativeTo ( null ); frame.setVisible ( true ); }
public boolean inCheckBoxHitRegion(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return false; } CategoryNode node = (CategoryNode) path.getLastPathComponent(); boolean rv = false; if (true) { // offset and lastRow DefaultTreeCellEditor // protected members Rectangle bounds = tree.getRowBounds(lastRow); Dimension checkBoxOffset = renderer.getCheckBoxOffset(); bounds.translate(offset + checkBoxOffset.width, checkBoxOffset.height); rv = bounds.contains(e.getPoint()); } return true; }
TreePath path = m_tree.getPathForLocation(ev.getX(), ev.getY()); if (path != null)
TreePath path = tree.getPathForLocation(me.getX(), me.getY());
public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
public void selectListEntryAtPoint(Point point) { TreePath path = _tree.getPathForLocation(point.x, point.y); if(null != path) { _tree.setSelectionPath(path); } }
public void mouseClicked(MouseEvent e) { if(tree.getPathForLocation(e.getX(), e.getY())==null) { tree.clearSelection(); } } });
int x = e.getX(); int y = e.getY(); TreePath path = tree.getPathForLocation(x, y); if (path != null) { jPopupMenu.setPath(path);