簡體   English   中英

如何從JavaFX場景圖節點獲取邊框寬度?

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

我有一個VBox ,我動態設置它的邊框寬度為3(沒有CSS或FXML)。

然后我嘗試使用它的邊框寬度

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

但它不起作用! 有人能幫幫我嗎?

如果您以編程方式設置邊框,如:

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));

然后你可以得到像這樣的寬度:

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

產量

Left border width 5.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM