简体   繁体   English

Javafx HBox Hgrow(SOMETIMES)子滚动窗格节点如何获取宽度?

[英]Javafx HBox Hgrow(SOMETIMES) child scrollpane node how to get width?

I currently have a scrollpane that is included in an HBox Node and set with HBox.setHgrow(scrollpane, Priority.SOMETIMES); 我目前有一个滚动窗格,该滚动窗格包含在HBox节点中,并使用HBox.setHgrow(scrollpane, Priority.SOMETIMES);

Also, I have manually set the dimensions of this scrollpane through using: 另外,我通过使用以下命令手动设置了此滚动窗格的尺寸:

scrollpane.setPrefWidth(w);
scrollpane.setMaxWidth(mxw);
scrollpane.setMinWidth(mnw);

Having all this set, the pane is displayed as required in its parent node, and when no other nodes are within the parent HBox, the scrollpane occupies the whole space. 设置好所有这些之后,窗格将在其父节点中按需显示,并且当父HBox中没有其他节点时,滚动窗格将占据整个空间。

When I attempt to get the width of this scrollpane, I am unable to get the calculated with, and all the values seem to return 0; 当我尝试获取此滚动窗格的宽度时,无法获得计算所得的值,并且所有值似乎都返回0; I have attempted the following methods in order to obtain the real with: 我尝试了以下方法以获得实数:

scrollpane.getWidth(); // returns 0
scrollpane.getLayoutBounds.getWidth(); // returns 0
scrollpane.boundsInLocalProperty().get().getWidth; // returns 0
scrollpane.boundsInParentProperty().get().getWidth; // returns 0
scrollpane.widthProperty().get(); // returns 0
scrollpane.layoutBoundsProperty().get().getWidth(); // returns 0

I have also used scenicView v8.0.0 to check the actual value of the width (which is different from prefWidth), but I cannot seem to recover this value anywhere from the available methods on Scrollpane. 我还使用了ScenicView v8.0.0来检查width的实际值(与prefWidth不同),但是我似乎无法从Scrollpane上的任何可用方法中恢复该值。

I am not quite sure what I am missing here. 我不太确定我在这里缺少什么。

Any help solving this would be greatly appreciated. 任何解决此问题的帮助将不胜感激。

After doing some further research I discovered that the reason why all width values were set to 0 were simply because I was attempting to perform the calculations in the constructor of the class that was using the ScrollPane. 经过进一步研究,我发现所有宽度值都设置为0的原因仅仅是因为我试图在使用ScrollPane的类的构造函数中执行计算。

More specifically, at the constructor level, the scollpane is not yet rendered and therefore has no dimensional information in its properties, hence, no width value. 更具体地说,在构造函数级别,该scollpane尚未呈现,因此其属性中没有尺寸信息,因此没有宽度值。

Performing the scrollpane.getWidth() after the rendering has happened works and provides the right information. 渲染完成后执行scrollpane.getWidth()可以正常工作并提供正确的信息。

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

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