Java Reference
In-Depth Information
// First name field
GridPane.setHalignment(fNameFld, HPos.LEFT);
gridpane.add(fNameFld, 1, 0);
// Last name field
GridPane.setHalignment(lNameFld, HPos.LEFT);
gridpane.add(lNameFld, 1, 1);
// Save button
GridPane.setHalignment(saveButt, HPos.RIGHT);
gridpane.add(saveButt, 1, 2);
root.getChildren().add(gridpane);
Figure 14-8 depicts a small form containing UI controls laid out using a grid pane
layout node.
Figure 14-8 . Adding controls to a layout
How It Works
One of the greatest challenges in building user interfaces is how controls can be placed
onto the display area. When developing GUI applications, it is ideal for an application
to allow the users to move and adjust the size of their viewable area while maintaining
a pleasant user experience. Similar to Java Swing, JavaFX layout has stock layouts that
provide the most common ways to display UI controls on the scene graph. This recipe
demonstrates the GridPane class.
Recall Recipe 14-4, in which you implemented a custom layout to display compon-
ents in a grid-like manner. You may notice similarities, but we left a lot of implementa-
 
 
Search WWH ::




Custom Search