📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this tutorial, we will learn how to use the JavaFX GridPane class to create a grid layout in the JavaFX application.
GridPane places its nodes into a grid of rows and columns. Nodes may span multiple rows or columns. GridPane is the most flexible built-in layout pane.GridPane layout is represented by javafx.scence.layout.GridPane class. We just need to instantiate this class to implement GridPane.
The setGridLinesVisible() enables us to show the lines of the layout grid, which allows us to visually debug the layout.
JavaFX GridPane Layout Example
Let's create an example to demonstrate the use of GridPane Layout:
package com.javafx.examples.layout; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class GridPaneExample extends Application { @Override public void start(Stage primaryStage) throws Exception { Label firsName = new Label("First Name"); Label lastName = new Label("Last Name"); Label userName = new Label("User Name"); Label emailId = new Label("Email Id"); TextField textField1 = new TextField(); TextField textField2 = new TextField(); TextField textField3 = new TextField(); TextField textField4 = new TextField(); Button Submit = new Button("Submit"); GridPane root = new GridPane(); root.setHgap(8); root.setVgap(8); root.setPadding(new Insets(5)); Scene scene = new Scene(root, 400, 200); root.addRow(0, firsName, textField1); root.addRow(1, lastName, textField2); root.addRow(2, userName, textField3); root.addRow(3, emailId, textField4); root.addRow(4, Submit); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
Output
Related JavaFX Examples
- JavaFX GridPane Example
- JavaFX ColorPicker Example
- JavaFX DatePicker Example
- JavaFX MenuBar Example
- JavaFX Radio Button Example
- JavaFX TabPane Example
- JavaFX Accordion Example
- JavaFX Login Form Validation Example
- JavaFX Form Validation - Registration Form Validation Example
- JavaFX Line Chart Example
- JavaFX Area Chart Example
- JavaFX Scatter Chart Example
- JavaFX Bar Chart Example
- JavaFX Pie Chart Example
- JavaFX Select and Multi-Select Example
- JavaFX Check Box Example
- Java Calculator Project
Comments
Post a Comment
Leave Comment