首页 > 解决方案 > 单击按钮时JavaFX布局移动

问题描述

这是我的问题的 gif:

在此处输入图像描述

如您所见,按钮调整大小 (elevates?) 并自行移动其外部布局。

这是层次结构:

StackPane
    Group // for other content
    Group // The make hbox "wrap-content"
        HBox  // For the 2 buttons
            JfxToggleButton  // "This is test"
            JfxButton    // "Restart" button

唯一要添加的代码是我将 HBox 的组定位在 StackPane 的右上角,如下所示:

StackPane.setAlignment(hboxGroup, Pos.TOP_RIGHT)

只有StackPane这个问题,BorderPane没有。我使用的原因StackPane是因为我希望将控件放在主要内容之上

ToggleButtonHBox有填充。

实际上,填充和对齐并不重要,因为HBox移动相对无关。

顺便说一句,我正在使用jfonix 库进行按钮样式设置。

谢谢你的帮助。

编辑。:

对于那些将这个问题贡献给 JFoenix 的人,这与标准 JavaFX 控件相同:(跳转仍然发生,只是不太明显)

在此处输入图像描述

与我上面提到的相比,Hbox它位于 a 的顶部BorderPane,跳跃不会发生:

在此处输入图像描述

标签: javajavafxjfoenix

解决方案


我意识到AnchorPane没有这个问题。

所以这是最终的布局层次结构:

StackPane
    Group // Content behind
    AnchorPane // That restricts movement, keeps the buttons in place
        Group   // That keeps the background only around the buttons
            HBox // Keeps the buttons next to each other
                ToggleButton
                Button

所以我最终遇到了不允许点击的问题。AnchorPane这是通过设置AnchorPane

anchorPane.setPickOnBounds(false);

推荐阅读