我正在制作一个显示图像映射的UI,并将其包装到锚定窗格中,并将其自身包装到一个滚动窗格中。 我想在左下角添加一个覆盖图,显示坐标。 当然,即使调整视图大小并左右滚动我的地图,也必须显示此叠加层。 我尝试在锚板上使用约束,但向右滚动地图时坐标字段消失。 在这里,您可以看到我的层次结构以及我希望该字段保留的位置: 场景生成器视图 Thx用于解答。
I'm making this UI where an image map is displayed, wrapped into an anchor pane, itself wrapped into a scrollpane. I want to add an overlay at the bottom left corner, showing coordinates. This overlay must of course be visible even when resizing my view and scrolling my map left and right. I tried to use constraints with the anchorpane but the coordinates field disappears when scrolling the map rightward. Here you can see a view of my hierarchy and the position I want the field to remain : scene builder view Thx for your answers.
最满意答案
SplitPane └AnchorPane ├ScrollPane │ └... └Label(etc)为了重叠标签,我推荐上述构造。 这是因为标签不在视口中,因此视口变焦和变换更容易。
考虑到水平ScrollBar不可见的情况,标签的LayoutY应该使用绑定进行计算。
// These can be set in Scene Builder anchorPane.getChildren().addAll(scrollPane, label); AnchorPane.setTopAnchor(scrollPane, 0.0); AnchorPane.setLeftAnchor(scrollPane, 0.0); AnchorPane.setRightAnchor(scrollPane, 0.0); AnchorPane.setBottomAnchor(scrollPane, 0.0); AnchorPane.setLeftAnchor(label, 0.0); // Bind LayoutY of Label DoubleBinding labelLayoutYBinding = Bindings.createDoubleBinding( () -> scrollPane.getViewportBounds().getHeight() - label.getHeight(), label.heightProperty(), scrollPane.viewportBoundsProperty()); labelLayoutYBinding.addListener((o, ov, nv) -> label.setLayoutY(nv.doubleValue()));如果水平ScrollBar总是显示在您的应用程序中,则在Scene Builder中设置固定的底部偏移量会比使用绑定更容易。
// This can be set in Scene Builder AnchorPane.setBottomAnchor(label, 13.0); // Set the fixed value to ease up SplitPane └AnchorPane ├ScrollPane │ └... └Label(etc)To overlap the label, I recommend the above construction. This is because the label is out of the viewport, making the viewport zoom and transform easier.
Considering a case horizontal ScrollBar is invisible, LayoutY of the label should be compute using binding.
// These can be set in Scene Builder anchorPane.getChildren().addAll(scrollPane, label); AnchorPane.setTopAnchor(scrollPane, 0.0); AnchorPane.setLeftAnchor(scrollPane, 0.0); AnchorPane.setRightAnchor(scrollPane, 0.0); AnchorPane.setBottomAnchor(scrollPane, 0.0); AnchorPane.setLeftAnchor(label, 0.0); // Bind LayoutY of Label DoubleBinding labelLayoutYBinding = Bindings.createDoubleBinding( () -> scrollPane.getViewportBounds().getHeight() - label.getHeight(), label.heightProperty(), scrollPane.viewportBoundsProperty()); labelLayoutYBinding.addListener((o, ov, nv) -> label.setLayoutY(nv.doubleValue()));If the horizontal ScrollBar is always displayed in your application, setting fixed bottom offset in Scene Builder is easier rather than using the binding.
// This can be set in Scene Builder AnchorPane.setBottomAnchor(label, 13.0); // Set the fixed value to ease up更多推荐
显示,map,view,滚动,电脑培训,计算机培训,IT培训"/> <meta name="description&qu
发布评论