JavaFx GridPane layout how to set margin for an element in row?

Deadly 提交于 2020-01-24 02:57:06

问题


I'm using GridPane layout for positioning things in my application. I'm wondering how I can set margin for an element in row

         GridPane.setConstraints(chip5, 1, 1, 1, 1, HPos.RIGHT, VPos.TOP); //I want to set 
       //  margin for chip5 from top (for example 5px)

Is it possible in GridPane?


回答1:


You can set the margin for any particular Node:

GridPane.setMargin(chip5, new Insets(5, 0, 0, 0));



回答2:


In FXML, you can do it as follows:

<TextField fx:id="txtFirstName" GridPane.rowIndex="0" GridPane.columnIndex="1">
    <GridPane.margin>
        <Insets right="30"/>
    </GridPane.margin>
</TextField>


来源:https://stackoverflow.com/questions/32634470/javafx-gridpane-layout-how-to-set-margin-for-an-element-in-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!