MouseListener () { return new MouseEventAdapter<>(super.createMouseListener()) { @Override public void mouseDragged(MouseEvent event) { JTree tree = (JTree)event.getSource(); Object property = tree.getClientProperty("DnD Source"); // DnDManagerImpl.SOURCE_KEY if (property == null) { super.mouseDragged(event); // use Swing-based DnD only if custom DnD is not set } } @Override protected @NotNull MouseEvent convert(@NotNull MouseEvent event) { if (!event.isConsumed() && SwingUtilities.isLeftMouseButton(event)) { int x = event.getX(); int y = event.getY(); JTree tree = (JTree)event.getSource(); if (tree.isEnabled()) { TreePath path = getClosestPathForLocation(tree, x, y); if (path != null && !isLocationInExpandControl(path, x, y)) { Rectangle bounds = getPathBounds(tree, path); if (bounds != null && bounds.y <= y && y <= (bounds.y + bounds.height)) { x = Math.max(bounds.x, Math.min(x, bounds.x + bounds.width - 1)); if (x != event.getX()) { event = convert(event, tree, x, y); } } } } } return event; } }; }