加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

javafx-2 – 通过java fx css为单个元素的配置边距

发布时间:2020-12-14 17:40:48 所属栏目:Java 来源:网络整理
导读:我有以下fxml片段: VBox fx:id="paneLeft" TextField promptText="Password"/ Button fx:id="btnLogin" text="Login" maxWidth="10000"/ Hyperlink text="Registration"/ /VBox 我需要在Button和超链接之间添加一个10px的间距.我也想使用CSS来完成这个任务.
我有以下fxml片段:
<VBox fx:id="paneLeft">
        <TextField promptText="Password"/>
        <Button fx:id="btnLogin" text="Login" maxWidth="10000"/>
        <Hyperlink text="Registration"/>
    </VBox>

我需要在Button和超链接之间添加一个10px的间距.我也想使用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>

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读