我有一个带菜单顶部的边框 Pane ,左侧有一个网格,中间有一个图像。我希望图像与边框中心的大小相同,因为现在图像越过我的网格。
我试过这个:
imageView.fitWidthProperty().bind(box.widthProperty());
其中 imageView 是我的图像的名称,而 box 是 BorderPane 对象。谢谢。
最佳答案
请参阅 JavaFX 功能请求 RT-21337 Add ImageViewPane and MediaViewPane controls 其中包含示例的代码附件 ImageViewPane
将调整 ImageView
大小的实现它包含该区域可用的区域。要获得所需的行为,您可能还需要实现 computeMinWidth和 computeMinHeight在 ImageViewPane
以便它们返回零而不是图像的最小尺寸。
now the image goes over my grid
这是因为您的图像的最小尺寸当前大于 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.
防止中心内容溢出边界的一些潜在替代方案:
ImageView
的大小如 ImageViewPane
上面链接的示例。 ImageView
在 ScrollPane . ImageView
. I tried this:
imageView.fitWidthProperty().bind(box.widthProperty());
我从提供的代码中猜测这是行不通的,因为图像的封闭框是某种可动态调整大小的 Pane ,因此框的最小宽度由图像的宽度决定,反之亦然。
关于image - JavaFx 图像大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15951284/