Defining layout and visuals

General

Defining spacings between controls

Spacings between controls can be defined in various ways in JavaFX.The preferred way of defining spacings between controls is using external CSS files. The concrete naming of the style can be found in the official documentation. The default JavaFX Pane classes offer so called constraints. Some of them can be used to define the spacings between controls. An example are margins for items added to a GridPane. It's not recommended to use spacing-related constraints. Use a combination of padding (-fx-padding) and appropriate spacing styles specific to the Pane class. For GridPanes and FlowPanes this is -fx-hgap and -fx-vgap, for HBox and VBox it's -fx-spacing.

So the goal here is to use the FXML mainly for control hierarchy and assigning styles only. Spacings should also not be defined directly in the code if possible.

Using common styles

-- ChristianHillbricht - 13 Apr 2018
Topic revision: r4 - 13 Apr 2020, JuttaFitzek
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback