在将节点拖动到ScrollPane的可见区域之外时要触发滚动 [英] Want to trigger scroll when dragging node outside the visible area in ScrollPane

查看:76
本文介绍了在将节点拖动到ScrollPane的可见区域之外时要触发滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在开发一个使用ScrollPane的应用程序,其中包含一个AnchorPane,该AnchorPane可以根据放置在工作区中的节点的不同而增长.我们能够将节点放置在工作空间上,并能够使用鼠标拖动事件将其拖动到不同的位置.

We have been working on an application that uses a ScrollPane containing an AnchorPane that can grow depending on what nodes get placed on the workspace. We are able to place nodes on the workspace and are able to drag them to different positions using mouse drag events.

我现在试图实现的是一种在我们拖动节点并且它碰到可见工作区边缘时自动滚动工作区的方法.我已经能够检测到节点开始移出可见区域的时间点,并且能够根据节点是垂直移动还是水平移动来设置vvalue或hvalue来移动滚动条.这在一定程度上起作用.

What I am now trying to implement is a way to automatically scroll the workspace when we are dragging a node and it touches the edge of the visible workspace. I have been able to detect the point when the node begins to move out of the visible area and I am able to move the scroll bar by setting the vvalue or hvalue depending on whether the node has moved vertically or horizontally. This is working to a certain extent.

当我将节点移至右侧并更新hvalue时,工作空间将滚动,设备将移至左侧,但鼠标停留在原来的位置,这意味着光标现在不在所拖动的节点上.我一直在尝试找到一种方法来将光标位置移动与我们滚动的距离相同的距离,以使其相对于要拖动的节点保持在相同的位置.

When I move a node off to the right and update the hvalue, the workspace is scrolled, the device shifts to the left but the mouse stays where it was meaning that the cursor is now not over the node that is being dragged. I have been trying to find a way to shift the cursor position by the same distance that we have scrolled so that it remains in the same position relative to the node that is being dragged.

我一直在寻找有关如何执行此操作的信息,并正在阅读Javadocs来尝试寻找解决方案,但均未成功.有人可以建议如何实现吗?谢谢.

I have been searching for information about how to do this and reading the Javadocs to try to find a solution without any success. Can someone please advise how to achieve this? Thanks.

推荐答案

我在TreeTableView中也遇到了类似的问题,并通过检测DragEnter/DragExit事件并启动一个TimeLine来解决它,具体取决于检测到DragExit事件.

I've had a similar problem with a TreeTableView and solved it by detecting DragEnter/DragExit events and starting a TimeLine that will scroll up/down depending on where the DragExit event was detected.

    private void setupScrolling() {
        scrolltimeline.setCycleCount(Timeline.INDEFINITE);
        scrolltimeline.getKeyFrames().add(new KeyFrame(Duration.millis(20), "Scoll", (ActionEvent) -> { dragScroll();}));
        tree.setOnDragExited(event -> {
            if (event.getY() > 0) {
                scrollDirection = 1.0 / tree.getExpandedItemCount();
            }
            else {
                scrollDirection = -1.0 / tree.getExpandedItemCount();
            }
            scrolltimeline.play();
        });
        tree.setOnDragEntered(event -> {
            scrolltimeline.stop();
        });
        tree.setOnDragDone(event -> {
            scrolltimeline.stop();
        });         
    }

完整示例: http://programmingtipsandtraps.blogspot.co.at/2015/10/drag-and-drop-in-treetableview-with.html

这篇关于在将节点拖动到ScrollPane的可见区域之外时要触发滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆