I am trying to put squares to the application window. I am using gridpane and ı need to put 16 square with 4x4 array . With gridpane ı can create 3 row 4 column array , however ı can't put squares to the bottom row. Here is my code and results :
public void start(Stage primaryStage) throws Exception {
GridPane grid = new GridPane();
Scene scene = new Scene(grid, 400, 400);
Image image = new Image("Pipe_Vertical.jpg");
Image image2 = new Image("Empty.jpg");
ImageView imageView = new ImageView(image2);
imageView.setFitHeight(100);
imageView.setFitWidth(100);
ImageView imageView2 = new ImageView(image2);
imageView2.setFitHeight(100);
imageView2.setFitWidth(100);
ImageView imageView3 = new ImageView(image2);
imageView3.setFitHeight(100);
imageView3.setFitWidth(100);
ImageView imageView4 = new ImageView(image2);
imageView4.setFitHeight(100);
imageView4.setFitWidth(100);
ImageView imageView5 = new ImageView(image2);
imageView5.setFitHeight(100);
imageView5.setFitWidth(100);
ImageView imageView6 = new ImageView(image2);
imageView6.setFitHeight(100);
imageView6.setFitWidth(100);
grid.add(imageView3, 0, 0);
grid.add(imageView4, 1, 0);
grid.add(imageView2, 2, 0);
grid.add(imageView, 3, 0);
grid.add(imageView5, 0, 1);
grid.add(imageView6, 3, 3);
primaryStage.setTitle("Test");
primaryStage.setScene(scene);
primaryStage.show();
And this is what it looks when ı run it : Test Results :
grid.add(imageView6, 3, 3);
this part of the code should have put the square to the bottom right side but it is appearing on the wrong place.
Problem Solved. Needed to use
for (int i = 0; i < 4; i++) { RowConstraints row = new RowConstraints(100); grid.getRowConstraints().add(row); }
It creates 4 rows with 100 pixel height.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.