How to do it...

  1. 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));
  1. 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);
  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{ ...

Get Java 11 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.