简体   繁体   English

如何从JavaFX场景图节点获取边框宽度?

[英]How to get border width from a JavaFX scene graph node?

I have a VBox and I set its border width to 3 dynamically (without CSS or FXML). 我有一个VBox ,我动态设置它的边框宽度为3(没有CSS或FXML)。

Then I tried to get its border width using 然后我尝试使用它的边框宽度

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

But it doesn't work! 但它不起作用! Can anybody help me please? 有人能帮帮我吗?

If you have set the border programatically like: 如果您以编程方式设置边框,如:

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 widths like: 然后你可以得到像这样的宽度:

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

Output 产量

Left border width 5.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM