简体   繁体   中英

JavaFX Borderpane combined with Splitpane

I'm very new to JavaFX. For a school project, I have to create a JavaFX application with three sectors (Left, Center, and bottom) which have to be resizable by dragging the divider line.

To create this layout I tried to use a BorderPane (for the sections) and combine it with a SplitPane to make it resizable. But I cannot figure out how to combine it. Is this even possible or do I need another Pane-Object?

BorderPane root = new BorderPane();
SplitPane splitPane = new SplitPane();
ScrollPane leftPane = new ScrollPane(new Button("Button 1"));
ScrollPane bottomPane = new ScrollPane(new Button("Button 2"));
FlowPane centerPane = new FlowPane(new Button("Button 3"));

//splitPane.getItems().addAll(leftPane, centerPane, bottomPane);
//root.getChildren().add(splitPane);
root.setLeft(leftPane);
root.setCenter(centerPane);
root.setBottom(bottomPane);

Just use two SplitPanes with different orientations (and forget about the BorderPane ):

package org.example;

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class SplitPanesExampleApp extends Application {

    @Override
    public void start(Stage stage) {

        // Creating the controls:
        ScrollPane leftPane = new ScrollPane(new Button("Left")),
                bottomPane = new ScrollPane(new Button("Bottom"));

        FlowPane centerPane = new FlowPane(new Button("Center (or right)"));

        SplitPane horizontalSplitPane = new SplitPane(leftPane, centerPane),
                verticalSplitPane = new SplitPane(horizontalSplitPane, bottomPane);

        // Setting orientations:
        verticalSplitPane.setOrientation(Orientation.VERTICAL);
        // horizontalSplitPane.setOrientation(Orientation.HORIZONTAL); // horizontal is the default value

        // Setting initial divider positions:
        verticalSplitPane.getDividers().get(0).setPosition(.8);
        horizontalSplitPane.getDividers().get(0).setPosition(.2);

        // Prepare and show stage:
        stage.setScene(new Scene(verticalSplitPane, 600, 400));
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM