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 9 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.