Add border around VBox in javafx?

Mikael picture Mikael · Nov 10, 2015 · Viewed 14.5k times · Source

IS it possible to add a borderline around a whole content of a VBox in Javafx?

Meaning i have added a lot of components already in tis VBox but want to have a border around it?

So if i have the css file like this:

#vbox_style {
    -fx-border-color: black;
    -fx-border-insets: 5;
    -fx-border-width: 3;
    -fx-border-style: dashed;
 }

How could i get this Resource, where do the file need to be located to use method as: myBox.setId("vbox_style");

Answer

user1438038 picture user1438038 · Nov 10, 2015

You can set a custom CSS style on the VBox:

String cssLayout = "-fx-border-color: red;\n" +
                   "-fx-border-insets: 5;\n" +
                   "-fx-border-width: 3;\n" +
                   "-fx-border-style: dashed;\n";

VBox yourBox = new VBox();   
yourBox.setStyle(cssLayout);