import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class TestApp extends Application {

    @Override
    public void start(Stage stage) {
        // create three CustomVBox containers (styled to have 20 spacing)
        final CustomVBox customVBox1 = createCustomVBox();
        final CustomVBox customVBox2 = createCustomVBox();
        final CustomVBox customVBox3 = createCustomVBox();

        // set spacing on the first CustomVBox to 40 - this fails:
//        customVBox1.setSpacing(40);

        // set spacing on the second or third CustomVBox to 40 - this will work fine
         customVBox2.setSpacing(40);

        Scene scene = new Scene(new HBox(20, customVBox1, customVBox2, customVBox3), 400, 200);
        stage.setScene(scene);
        stage.show();
    }

    private CustomVBox createCustomVBox() {
        final CustomVBox customVBox = new CustomVBox();
        final Label spacingLabel = new Label("spacing: " + customVBox.getSpacing());
        customVBox.getChildren().addAll(new Label("Label"), spacingLabel);
        customVBox.spacingProperty().addListener((obs, ov, nv) -> spacingLabel.setText("spacing " + nv));
        return customVBox;
    }

    public static void main(String[] args) {
        launch(args);
    }

    public static class CustomVBox extends VBox {

        public CustomVBox() {
            getStyleClass().addAll("custom-vbox");
        }

        public String getUserAgentStylesheet() {
            return getClass().getResource("styling.css").toExternalForm();
        }
    }
}