[英]JavaFX Borderpane combined with Splitpane
I'm very new to JavaFX.我对 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.对于学校项目,我必须创建一个 JavaFX 应用程序,该应用程序具有三个扇区(左、中和下),必须通过拖动分隔线来调整大小。
To create this layout I tried to use a BorderPane (for the sections) and combine it with a SplitPane to make it resizable.为了创建此布局,我尝试使用 BorderPane(用于部分)并将其与 SplitPane 组合以使其可调整大小。 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
):只需使用两个具有不同方向的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.