Java Reference
In-Depth Information
tion features out, such as adjusting min/max sizes, padding, and vertical alignments.
Amazingly, the JavaFX team has created a robust grid-like layout called the
GridPane .
First you create an instance of a GridPane . Next, you set the padding by using an
instance of an Inset object. After setting the padding, you simply set the horizontal
and vertical gap. The following code snippet instantiates a grid pane ( GridPane ) with
padding, horizontal, and vertical gaps set to 5 (pixels):
GridPane gridpane = new GridPane();
gridpane.setPadding(new Insets(5));
gridpane.setHgap(5);
gridpane.setVgap(5);
The padding is the top, right, bottom, and left spacing around the region's content
in pixels. When obtaining the preferred size, the padding will be included in the calcu-
lation. Setting the horizontal and vertical gaps relate to the spacing between UI controls
within the cells.
Next, simply place each UI control into its respective cell location. All cells are
zero relative. Following is a code snippet that adds a Save button UI control into a grid
pane layout node ( GridPane ) at cell (1, 2):
gridpane.add(saveButt, 1, 2);
The layout also allows you to horizontally or vertically align controls in the cell.
The following code statement right-aligns the Save button:
GridPane.setHalignment(saveButt, HPos.RIGHT);
14-8. Generating Borders
Problem
You want to create and customize borders around an image.
Solution
Search WWH ::




Custom Search