JavaFX - SplitPane, resize & proportions


Question

How can I achieve proportional resize of whole SplitPane?

public class JfxSplitPaneTest extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        SplitPane split = new SplitPane();
        StackPane child1 = new StackPane();
        child1.setStyle("-fx-background-color: #0000AA;");
        StackPane child2 = new StackPane();
        child2.setStyle("-fx-background-color: #00AA00;");
        StackPane child3 = new StackPane();
        child3.setStyle("-fx-background-color: #AA0000;");
        split.getItems().addAll(child1, child2, child3);
        //split.setDividerPositions(0.1f, 0.6f, 0.9f)
        stage.setScene(new Scene(split, 400, 300));
        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

Start the program:

enter image description here

Set dividers how I like them:

enter image description here

Make window width really small (I continued and made it even smaller, no pic):

enter image description here

Resize back and observe that dividers are neither how I set them nor how they were when program started.

enter image description here

Doing this makes it closer to what I'd expect:

    child1.setMinWidth(Region.USE_PREF_SIZE)
    child1.setPrefWidth(100)
    child2.setMinWidth(Region.USE_PREF_SIZE)
    child2.setPrefWidth(200)
    child3.setMinWidth(Region.USE_PREF_SIZE)
    child3.setPrefWidth(300)

except that dividers are initally at wrong position (until I resize SplitPane, 1px is enough) and when shrinking window width, dividers are inside components.

How can I make this work please?

1
8
3/10/2013 4:04:49 PM

Try to add Change Listener to stage.widthProperty() and stage.heightProperty(). And call this:

    split.setDividerPositions(0.1f, 0.6f, 0.9f)
2
9/27/2013 11:34:11 AM

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