1-8. Adding Components to a Layout

Problem

You want to create a simple form application by adding UI components to a layout similar to a grid-like display.

Solution

Use JavaFX’s javafx.scene.layout.GridPane class. This source code implements a simple UI form containing a first and last name field controls using the grid pane layout node (javafx.scene.layout.GridPane):

        GridPane gridpane = new GridPane();         gridpane.setPadding(new Insets(5));         gridpane.setHgap(5);         gridpane.setVgap(5);         Label fNameLbl = new Label("First Name");         TextField fNameFld = new TextField();         Label lNameLbl = new Label("First Name");         TextField lNameFld = new TextField();         Button saveButt = new Button("Save"); ...

Get JavaFX 2.0: Introduction by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.