有什么方法可以设置GridPane的列数和行数?
我目前有这样的事情:
<fx:root type="GridPane" xmlns:fx="http://javafx.com/fxml"
stylesheets="view/Style.css"
maxHeight="Infinity" maxWidth="Infinity">
<gridLinesVisible>true</gridLinesVisible>
<children>
<Pane fx:id="center"
GridPane.columnIndex="1" GridPane.rowIndex="1"
GridPane.columnSpan="5" GridPane.rowSpan="3"
GridPane.hgrow="always" GridPane.vgrow="always"/>
<Pane fx:id="options"
GridPane.columnIndex="0" GridPane.rowIndex="5"
GridPane.columnSpan="6"/>
</children>
</fx:root>
然后在其中动态添加元素。
问题来了,如果行/列没有任何元素被删除,那么窗格的外观就很奇怪(例如将元素添加到(3,0)然后在(2,X),(1 ,X)(3,0)上的元素不会在窗格上居中,因为(4,X)和(5,X)上没有元素
最佳答案
使用普通HBox和VBox
HBox HB = new HBox();
HB.getChildren().addAll(btnexample1, btnexample2);
GridPane.setHalignment(HB, HPos.LEFT);
HB.setSpacing(5);
grid.add(HB, 0, 8);
关于java - 设置GridPane列/行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15429784/