JavaFX 8. Resize of SplitPane within BorderPane


I have the following layout in JavaFx 8 defined via .fxml:

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="730.0" prefWidth="1005.0" xmlns="" xmlns:fx="">
      <Pane fx:id="statusPane" prefHeight="30.0" prefWidth="1005.0" BorderPane.alignment="CENTER" />
      <SplitPane fx:id="mainPane" dividerPositions="0.2" prefHeight="700.0" prefWidth="1005.0"  minHeight="-Infinity" minWidth="-Infinity" BorderPane.alignment="CENTER">
            <ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="ALWAYS" vbarPolicy="ALWAYS" minHeight="-Infinity" minWidth="-Infinity">
                  <AnchorPane fx:id="menuPane" prefHeight="700.0" prefWidth="200.0"  minHeight="-Infinity" minWidth="-Infinity" />
            <ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="ALWAYS" vbarPolicy="ALWAYS"  minHeight="-Infinity" minWidth="-Infinity">
                  <AnchorPane fx:id="formPane" prefHeight="700.0" prefWidth="800.0"  minHeight="-Infinity" minWidth="-Infinity"/>

I do not understand why SplitPane cannot get smaller than 1005x700 when user is resizing BorderPane during the runtime. SplitPane can get larger than 1005x700, which is fine, but it cannot get smaller than prefHeight and prefWidth, thought the Application window itself (BorderPane) can.


10/7/2014 12:36:12 PM

Accepted Answer

OK. I found the problem!

 minHeight="-Infinity" minWidth="-Infinity"

generated by Scene Builder was a very bad idea!

The following code

 minHeight="0" minWidth="0"

works as expected!

So do not use -Infinity constant for the minHeight or minWidth. 0 is what you need!

10/7/2014 2:39:52 PM

The size of Layouts doesn't only depend on its size, but the size of the container(parent) / contents(children) as well

From Docs

A pane's parent will resize the pane within the pane's resizable range during layout.

The size of the SplitPane depends on its Parent. Since the Width of BorderPane is 1005.0 and Height is 730.0. The SplitPane fills the Parent(which it is supposed to)

Try removing the

prefHeight="730.0" prefWidth="1005.0"

from the BorderPane in above fxml, you can find the SplitPane will decrease in height.

Why only height? It is because

<Pane fx:id="statusPane" prefHeight="30.0" prefWidth="1005.0" ..

forces the BorderPane to not decrease it's width.

Parent has to resize itself depending on the size of its child.

In short, if you are not sure how big or small your window can be, don't specify the prefHeight or prefWidth to your layouts

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow