java - 单击按钮时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
是因为我希望将控件放在主要内容之上。
ToggleButton
并HBox
有填充。
实际上,填充和对齐并不重要,因为HBox
移动相对无关。
顺便说一句,我正在使用jfonix 库进行按钮样式设置。
谢谢你的帮助。
编辑。:
对于那些将这个问题贡献给 JFoenix 的人,这与标准 JavaFX 控件相同:(跳转仍然发生,只是不太明显)
与我上面提到的相比,Hbox
它位于 a 的顶部BorderPane
,跳跃不会发生:
解决方案
我意识到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);
推荐阅读
- php - 我想将 GuzzleHttp 与 Socks5 代理一起使用
- if-statement - 在 QUERY 公式中使用 IF 函数(Google 表格)
- google-apps-script - 带有 ui.prompt 命令的“例外:参数不能为空:按钮”。为什么?
- python - 模型是否完全使用 .fit() 在 sklearn 和 tensorflow 中重新训练
- classification - 如何解决 Python 中的“ValueError:找到样本数量不一致的输入变量”问题
- html - 如何修复我的乳胶数学术语的宽度和高度?
- ios - 在视图结构中初始化成员
- node.js - 无法运行反应项目-以下错误 enoent ENOENT
- c++ - 在 C++ 中使用模板编写函数出现分段错误
- javascript - 在 CKEDITOR.on instanceReady 之后,Firefox 中的 editor.editor.document 未定义