JavaFX如何滚动ScrollPane使节点位于视图端口的中间? [英] JavaFX How to scroll ScrollPane to have node in the middle of view port?

查看:197
本文介绍了JavaFX如何滚动ScrollPane使节点位于视图端口的中间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用显示当前时间的行创建时间轴。我正在使用AnchorPane添加放置在ScrollPane中的行。我需要模拟1天,滚动窗格宽度为(2880px,每60px为1小时)。我的限制是(前一天12小时,第二天12小时)。移动我的线路工作正常。

I have to create timeline with line showing current time. I'm using AnchorPane with added line placed in ScrollPane. I need to simulate 1 day, scrollpane width is ( 2880px, every 60px is one hour). My limits are ( previous day 12hour, and next day 12 hour). Moving my line is working fine.

我需要做的就是在视口中间设置线路并在其下移动内容。
对于移动线我正在使用这种方法:

All I need to do is to set line in the middle of view port and move content under it. For moving line i'm using this method:

scrollPane.setHvalue( line.getStartX() - anchorPane.width); 

它的工作很好。内容正在移动,但线路正在向前发展。我在线路为0:00(位置设置为0.25)时开始,当位置为(0.75)24 h时结束。
我也缩放我的时间轴Y轴所以

It is working "kind of fine". Content is moving but line is moving to. I'm starting when the line is 0:00 ( position is set to 0.25 ) and finishing when position is ( 0.75 ) 24 h. I'm also scaling my time line axis Y so

/* where line position is calculate by scale, scale is x2, x3, x4.... */
scrollPane.setHvalue( line.getStartX() - anchorPane.width * scale); 

请参阅imgs for hours:0:00,12:00,24:00 ...
正确的行位置仅在12:00 ...如何修改函数来设置行的位置?

Please see imgs for hours: 0:00, 12:00, 24:00... Correct line position is only at 12:00... How to modificate function to set position of the line?



推荐答案

我不知道我是否完全明白你的问题。在我看来,你有一个滚动窗格,上面有一个绿线节点,不是吗?如果是这样......

I do not know if I quite understand your question. What appears to me is that you have a scroll pane with a node of a green line on top of it, is not it? If so ...

如果绿线是一个节点,也许你可以为滚动窗格的显示值注册一个事件处理程序(hvalue,i belive)。例如,每次修改滚动窗格的滚动值时,都应该更新绿线节点的平移位置。我不是布局方面的专家。 JavaFX对我来说还是新手。但据我所知,似乎可以做到。从理论上讲,这显然可以做到。

If the green line is a node, maybe you can register an event handler for the display value of the scroll pane (hvalue, i belive). For example, every time the scroll value of the scroll pane is modified, an update on the translational position of the Green Line node should be made. I'm no expert on layouts. JavaFX is still new to me. But from what I know, it seems it can be done. In theory, this can apparently be done.

这篇关于JavaFX如何滚动ScrollPane使节点位于视图端口的中间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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