簡體   English   中英

JavaFX Borderpane 與 Splitpane 結合

[英]JavaFX Borderpane combined with Splitpane

我對 JavaFX 很陌生。 對於學校項目,我必須創建一個 JavaFX 應用程序,該應用程序具有三個扇區(左、中和下),必須通過拖動分隔線來調整大小。

為了創建此布局,我嘗試使用 BorderPane(用於部分)並將其與 SplitPane 組合以使其可調整大小。 但我不知道如何組合它。 這甚至可能還是我需要另一個窗格對象?

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);

只需使用兩個具有不同方向的SplitPanes (忘記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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM