Gaming News | Gaming Opinion | Playstation 4 | Xbox One | PS Vita | Film | Media

JavaFX – GridPane

The article will provide a user with information on JavaFx – gridpane. It will also advise a user on how to create a gridpane.
The GridPane layout pane enables you to create a flexible grid of rows and columns in which to lay out nodes. Nodes can be placed in any cell in the grid and can span cells as needed. A grid pane is useful for creating forms or any layout that is organized in rows and columns.

Gap properties can be set to manage the spacing between the rows and columns. The padding property can be set to manage the distance between the nodes and the edges of the grid pane. Let’s see how to create a grid pane. In order to create a gridpane, please use the code as provided below:

GridPane grid = new GridPane();
grid.setPadding(new Insets(0, 0, 0, 10));

// Category in column 2, row 1
Text category = new Text(“Sales:”);
category.setFont(Font.font(“Tahoma”, FontWeight.BOLD, 20));
grid.add(category, 1, 0);

// Title in column 3, row 1
Text chartTitle = new Text(“Current Year”);
chartTitle.setFont(Font.font(“Tahoma”, FontWeight.BOLD, 20));
grid.add(chartTitle, 2, 0);

// Subtitle in columns 2-3, row 2
Text chartSubtitle = new Text(“Goods and Services”);
grid.add(chartSubtitle, 1, 1, 2, 1);

// House icon in column 1, rows 1-2
ImageView imageHouse = new ImageView(
new Image(LayoutSample.class.getResourceAsStream(“graphics/house.png”)));
grid.add(imageHouse, 0, 0, 1, 2);

// Left label in column 1 (bottom), row 3
Text goodsPercent = new Text(“Goods\n80%”);
GridPane.setValignment(goodsPercent, VPos.BOTTOM);
grid.add(goodsPercent, 0, 2);

// Chart in columns 2-3, row 3
ImageView imageChart = new ImageView(
new Image(LayoutSample.class.getResourceAsStream(“graphics/piechart.png”)));
grid.add(imageChart, 1, 2, 2, 1);

// Right label in column 4 (top), row 3
Text servicesPercent = new Text(“Services\n20%”);
GridPane.setValignment(servicesPercent, VPos.TOP);
grid.add(servicesPercent, 3, 2);

border.setCenter(grid); // Add to BorderPane
The last line of code adds the grid pane to the center region of a border pane.

If a user has read the article then he/she would have gained knowledge on gridpane and also how to create a gridepane.

Leave a Comment