简体   繁体   English

JavaFx-在SceneBuilder中定位组件

[英]JavaFx— positioning components in SceneBuilder

I used the drag and drop interface to put the components where I want them to be, but when the window is resized they lose their relative position. 我使用拖放界面将组件放置在我想要的位置,但是当调整窗口大小时,它们会丢失其相对位置。 I have attached a screen shot of my hierarchy and of two windows to show how the components lose their position. 我已经附上了我的层次结构和两个窗口的屏幕快照,以显示组件如何失去位置。

Hierarchy Fullscreen 全屏 层次结构

If you want to use the AnchorPane to layout your components, you can set the Anchor Pane Constraints, like in the image below: 如果要使用AnchorPane布置组件,则可以设置Anchor Pane Constraints,如下图所示:

锚定窗格约束

This way it doesn't matter if you resize the screen, the button will always stay 10px far from the AnchorPane's right border. 这样,无论您调整屏幕大小都无所谓,该按钮始终与AnchorPane的右边框保持10px距离。

When you use the AnchorPane to place components on screen you are not going to have a relative positioning, You should use others containers to layout your application. 当您使用AnchorPane在屏幕上放置组件时,您将不会有相对的位置,应该使用其他容器来布局应用程序。 Read more about how to use Layout Panes here: Using Layout Panes 在此处阅读有关如何使用布局窗格的更多信息: 使用布局窗格

You need to study how to use Layout Panes . 您需要学习如何使用布局窗格 Dragging and dropping components results in absolute positioning, which really bad practice. 拖放组件会导致绝对定位,这确实是不好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM