How to get border width from JavaFX node scene graph?

I have it VBoxand I set the border width 3 dynamically (without CSS or FXML).

Then I tried to get the border width with

myVBox.getBorder().getStrokes().get(0).getLeftStrokeWidth();

But that will not work! Can anybody help me?

+4
source share
1 answer

If you set the border programmatically, for example:

VBox vbox = new VBox();
BorderStroke borderStroke = new BorderStroke(Color.RED, BorderStrokeStyle.DASHED, 
    null, new BorderWidths(5));
// Sets all 4 borders
vbox.setBorder(new Border(borderStroke));

Then you can get the width like:

double left = vbox.getBorder().getStrokes().get(0).getWidths().getLeft();
System.out.println("Left border width " + left);

Output

Left border width 5.0
+1
source

Source: https://habr.com/ru/post/1667721/


All Articles