JavaFX SplitPane create

Description

JavaFX SplitPane create

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {

   public static void main(String[] args) {
      Application.launch(Main.class, args);
   }//from  ww w  .  j  a v  a 2s. c om

   @Override
   public void start(Stage primaryStage) {
      primaryStage.setTitle("Split Views");
      Group root = new Group();
      Scene scene = new Scene(root, 350, 250, Color.WHITE);

      // Left and right split pane
      SplitPane splitPane = new SplitPane();
      splitPane.prefWidthProperty().bind(scene.widthProperty());
      splitPane.prefHeightProperty().bind(scene.heightProperty());

      // List<Node> items = splitPane.getItems();
      VBox leftArea = new VBox(10);

      for (int i = 0; i < 5; i++) {
         HBox rowBox = new HBox(20);
         rowBox.getChildren().add(new Label("" + i));
         leftArea.getChildren().add(rowBox);
      }
      leftArea.setAlignment(Pos.CENTER);

      // Upper and lower split pane
      SplitPane splitPane2 = new SplitPane();
      splitPane2.setOrientation(Orientation.VERTICAL);
      splitPane2.prefWidthProperty().bind(scene.widthProperty());
      splitPane2.prefHeightProperty().bind(scene.heightProperty());

      HBox centerArea = new HBox();
      centerArea.getChildren().add(new Label("Upper Right"));

      HBox rightArea = new HBox();

      rightArea.getChildren().add(new Label("Lower Right"));

      splitPane2.getItems().add(centerArea);
      splitPane2.getItems().add(rightArea);

      splitPane.getItems().add(leftArea);
      splitPane.getItems().add(splitPane2);

      ObservableList<SplitPane.Divider> dividers = splitPane.getDividers();
      for (int i = 0; i < dividers.size(); i++) {
         dividers.get(i).setPosition((i + 1.0) / 3);
      }

      HBox hbox = new HBox();
      hbox.getChildren().add(splitPane);
      root.getChildren().add(hbox);

      primaryStage.setScene(scene);
      primaryStage.show();
   }

}



PreviousNext

Related