JavaFX Borderpane without left and right children

自作多情 提交于 2019-12-12 02:39:22

问题


I wondering if there's a way to make Borderpane have the node set at the center to take up the full width of the window if there are no children in the left and right slots. I used Scene Builder to create the FXML file and currently, when I resize the window of the application, there are massive white spaces to the left, right, and bottom of the node in the center. Is there a way to get rid of them?

Here is what it currently looks like:


回答1:


If you have a Node centered in a BorderPane it will be resized to fill the remaining space in the center.

The top and bottom children will be resized to their preferred heights and extend the width of the border pane. The left and right children will be resized to their preferred widths and extend the length between the top and bottom nodes. And the center node will be resized to fill the available space in the middle. Any of the positions may be null.

But it gets resized using the layout bounds of the actual Node.

If you take a look on the documentation of maxWidth and maxHeight methods of Node:

Returns the node's maximum width(height) for use in layout calculations. If the node is resizable, its parent should not resize its width any larger than this value. A value of Double.MAX_VALUE indicates the parent may expand the node's width beyond its preferred without limits.

So, without seeing your actual code I guess the problem is that you have set the maximal size of your control that you have placed into the center of the BorderPane, therefore it does not get resized beyond that limit. As the documentation states you should set it to Double.MAX_VALUE to make the BorderPane able to resize it to fill the whole space left.



来源:https://stackoverflow.com/questions/37872241/javafx-borderpane-without-left-and-right-children

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!