- Let's create GridPane, which will hold the components in a grid of rows and columns:
GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setHgap(10); gridPane.setVgap(10); gridPane.setPadding(new Insets(25, 25, 25, 25));
- First, we will create a button and add two classes, btn, and btn-primary, to it. In the next step, we will define these selectors with the required CSS properties:
Button primaryBtn = new Button("Primary"); primaryBtn.getStyleClass().add("btn"); primaryBtn.getStyleClass().add("btn-primary"); gridPane.add(primaryBtn, 0, 1);
- Now let's provide the required CSS properties for the classes, btn and btn-primary. The selector for the classes are of the form .<class-name>:
.btn{ ...