JavaFX SplitPane

105 篇文章 5 订阅

The JavaFX SplitPane is a container control that can contain multiple other components inside it. In other words, the SplitPane is split between the controls it contains. Between the controls in the SplitPane is a divider. The user can move the divider to set how much space is allocated to each control. Here is a screenshot of a JavaFX SplitPane:

Full JavaFX SplitPane Example

The JavaFX SplitPane is represented by the JavaFX class javafx.scene.control.SplitPane. Here is a full JavaFX SplitPane example so you can get an idea about how using it looks:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SplitPaneExample extends Application {

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

    public void start(Stage primaryStage) {

        SplitPane splitPane = new SplitPane();

        VBox leftControl  = new VBox(new Label("Left Control"));
        VBox rightControl = new VBox(new Label("Right Control"));

        splitPane.getItems().addAll(leftControl, rightControl);

        Scene scene = new Scene(splitPane);

        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX App");

        primaryStage.show();
    }
}

Create a SplitPane

Before you can use a JavaFX SplitPlane you must first create a SplitPane instance. Here is an example of creating a JavaFX SplitPane:

SplitPane splitPane = new SplitPane();

Adding Controls to the SplitPane

In order to show anything inside the JavaFX SplitPane you must add some JavaFX controls to it. You do so via the SplitPane getItems().add(...) method. Here is an example of adding two controls to a JavaFX SplitPane:

SplitPane splitPane = new SplitPane();

VBox leftControl  = new VBox(new Label("Left Control"));
VBox rightControl = new VBox(new Label("Right Control"));

splitPane.getItems().addAll(leftControl, rightControl);

Adding More Than Two Controls to a SplitPane

You can add more than two controls to a JavaFX SplitPane. If you do, there will be a divider in-between each two controls. Here is a Java code example of adding 3 controls to a JavaFX SplitPane:

SplitPane splitPane = new SplitPane();

VBox leftControl  = new VBox(new Label("Left Control"));
VBox midControl   = new VBox(new Label("Mid Control"));
VBox rightControl = new VBox(new Label("Right Control"));

splitPane.getItems().addAll(leftControl, midControl, rightControl);

Scene scene = new Scene(splitPane);

primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX App");

primaryStage.show();

Here is a screenshot of how such a SplitPane with 3 controls added looks:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值