javafx-2 – 通过java fx 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>

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

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...