JavaFX - SplitPane, resize & proportions

后端 未结 3 1718
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 16:48

How can I achieve proportional resize of whole SplitPane?

public class JfxSplitPaneTest extends Application {
    @Override
    public void start(Stage stage         


        
相关标签:
3条回答
  • 2021-01-17 16:56

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

        split.setDividerPositions(0.1f, 0.6f, 0.9f)
    
    0 讨论(0)
  • 2021-01-17 17:05

    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
    });
    
    0 讨论(0)
  • 2021-01-17 17:06

    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?

    0 讨论(0)
提交回复
热议问题