我刚刚开始学习JavaFX,我制作了一个程序,在GridPane
中显示三个随机多米诺骨牌。我只是好奇为什么setHgap()方法创建垂直线而不是水平线,反之亦然?
下面的代码示例和图片:
public class Chapter_14_E03_DisplayThreeTiles extends Application {
public static void main(String[] args) {
Application.launch(args);
}
public void start(Stage primaryStage) {
// Create an arraylist to store number values
ArrayList<Integer> tileNumbers = new ArrayList<>();
for (int i = 1; i <= 36; i++)
tileNumbers.add(i);
java.util.Collections.shuffle(tileNumbers);
// Create a pane to hold the images
GridPane pane = new GridPane();
pane.setHgap(2); // Creates horisontal lines ???
// Add images to pane
for (int i = 0; i <= 2; i++) {
pane.add(new ImageView(new Image("file:image\\tiengow\\" + tileNumbers.get(i) + ".png")), i, 0);
}
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise_14_03");
primaryStage.setScene(scene);
primaryStage.show();
}
}
产生以下输出: