JavaFX场景生成器:调整大小时,将网格面板换成滚动窗格保留在角落(JavaFX Scene Builder : make gridpane wrapped into scrollpane rema

编程入门 行业动态 更新时间:2024-10-09 17:28:24
JavaFX场景生成器:调整大小时,将网格面板换成滚动窗格保留在角落(JavaFX Scene Builder : make gridpane wrapped into scrollpane remain in corner when resizing)

我正在制作一个显示图像映射的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

本文发布于:2023-07-19 07:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1175413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生成器   网格   面板   窗格   场景

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!