我必须创建显示当前时间的时间线。我正在使用 AnchorPane,并将添加的行放置在 ScrollPane 中。我需要模拟1天,滚动 Pane 宽度为(2880px,每60px为一小时)。我的限制是(前一天 12 小时,第二天 12 小时)。移动我的线路工作正常。
我需要做的就是在视口(viewport)中间设置线条并将内容移动到其下方。 对于移动线,我使用这种方法:
scrollPane.setHvalue( line.getStartX() - anchorPane.width);
它工作得“还不错”。内容在移动,但线条在移动。我在线路为 0:00(位置设置为 0.25)时开始,并在位置为(0.75)24 小时时结束。 我还缩放了时间轴 Y
/* where line position is calculate by scale, scale is x2, x3, x4.... */
scrollPane.setHvalue( line.getStartX() - anchorPane.width * scale);
请查看 imgs 的营业时间:0:00、12:00、24:00... 正确的线路位置仅在12:00...如何修改函数来设置线路位置?
最佳答案
该行必须位于滚动 Pane 内是否有原因?为什么不将其覆盖在整个滚动 Pane 上?
或参阅这篇有关使用绑定(bind)来修复滚动 Pane 内的节点的文章:Always visible when scrolled anchored Node in Java FX 2.0?
关于JavaFX 如何滚动 ScrollPane 以使节点位于视口(viewport)中间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18588536/