gpt4 book ai didi

javafx-2 - 如何使用 CSS 为 JavaFX 元素添加边距?

转载 作者:行者123 更新时间:2023-12-03 11:44:45 24 4
gpt4 key购买 nike

我有以下 FXML 片段:

<VBox fx:id="paneLeft">
<TextField promptText="Password"/>
<Button fx:id="btnLogin" text="Login" maxWidth="10000"/>
<Hyperlink text="Registration"/>
</VBox>

是否可以在 Button 之间添加 10px 的间距?和 Hyperlink使用 CSS 的元素?

提前致谢!

最佳答案

看来你不能。 JavaFX 目前对 CSS 的支持有限。

However, the CSS padding and margins properties are supported on some JavaFX scene graph objects.



说官方的 CSS 引用指南。因此,解决方法可能是使用额外的其他布局,例如另一个 VBox:
<VBox fx:id="paneLeft" spacing="10">
<VBox fx:id="innerPaneLeft">
<TextField promptText="Password"/>
<Button fx:id="btnLogin" text="Login" maxWidth="10000"/>
</VBox>
<Hyperlink text="Registration"/>
</VBox>

更新:
找到了一种更完美的方法,但仍然不是通过 CSS。
 <?import javafx.geometry.Insets?>

<VBox fx:id="paneLeft">
<TextField promptText="Password"/>
<Button fx:id="btnLogin" text="Login" maxWidth="10000">
<VBox.margin>
<Insets>
<bottom>10</bottom>
</Insets>
</VBox.margin>
</Button>
<Hyperlink text="Registration"/>
</VBox>

这避免了定义不必要的额外布局。

关于javafx-2 - 如何使用 CSS 为 JavaFX 元素添加边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16977100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com