当我使用 BorderPane 并将布局放在中心部分时,它会覆盖其他部分,如何防止中心部分覆盖 borderPane 中的其他部分
如您所见,表格覆盖了 BorderPane 的右侧部分。 我把 table 放在 Pane 里面。
最佳答案
来自BorderPane文档:
BorderPane does not clip its content by default, so it is possible that childrens' bounds may extend outside its own bounds if a child's min size prevents it from being fit within it space.
为了防止溢出,一些选项是:
- 您可以对子节点进行编码,使其没有最小大小。
- 您可以确保所有子项的最小尺寸之和至少等于边框 Pane 的最小尺寸。
您可以显式设置 clip在你的子节点上。有关演示,请参阅:JavaFX Pane Clipping .
final Rectangle outputClip = new Rectangle(); childNode.setClip(outputClip); childNode.layoutBoundsProperty().addListener((ov, oldValue, newValue) -> { outputClip.setWidth(newValue.getWidth()); outputClip.setHeight(newValue.getHeight()); });
您在边框 Pane 中设置子节点的顺序决定了哪个节点显示在顶部,因此如果所有节点都是不透明的,您可以先设置中心 Pane ,然后将侧面 Pane 绘制在任何溢出的上方。
关于javafx - BorderPane中心与其他部分重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41565090/