JavaFX - SplitPane, resize & proportions

谁都会走 提交于 2019-12-01 16:08:45

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

    split.setDividerPositions(0.1f, 0.6f, 0.9f)

Try to set the divisors like AS3Boyan said

split.setDividerPositions(0.1f, 0.6f, 0.9f)

and add this:

How can I avoid a SplitPane to resize one of the panes when the window resizes?

The rule of thumb is to use setDividerPositions with Platform.runLater when the resize event is triggered.

You probably want to start with a default ratio, let the user change that ratio, and maintain this ratio whatever it is when there's a resize event. Let's consider a 25/75 vertical FX splitPane in some stage:

splitPane.setDividerPositions(0.25f, 0.75f);
stage.heightProperty().addListener((obs, oldVal, newVal) -> {
    double[] positions = splitPane.getDividerPositions(); // reccord the current ratio
    Platform.runLater(() -> splitPane.setDividerPositions(positions)); // apply the now former ratio
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!