O'Reilly logo

JavaFX 2.0: Introduction by Example by Carl Dea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required