JavaFX | SplitPane Class - GeeksforGeeks

26 Sep, 2018
SplitPane class is a part of JavaFX. SplitPane class is a control which contains two or more sides separated by a divider. Sides can be dragged by the user to give more space to one of the sides which cause the other side to shrink by an equal amount. SplitPane class inherits Control class.
Constructor of the Class:
SplitPane(): Creates a new SplitPane.
SplitPane(Node... n): Creates a SplitPane with specified nodes.
Commonly Used Methods:
Below programs illustrate the use of SplitPane Class:
Java program to create a split pane and add labels to it:In this program, we will create a SplitPane name split_pane.Create and add labels to the split pane using getItems().add() function.Add the split_pane to the scene and add the scene to the stage.Call the show() function to display the final results.// Java program to create a split pane// and add labels to itimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.scene.layout.*;import javafx.scene.paint.*;import javafx.scene.text.*;import javafx.geometry.*;import javafx.scene.layout.*;import javafx.scene.shape.*;import javafx.scene.paint.*;import javafx.scene.*;import java.io.*;import javafx.scene.image.*;  public class SplitPane_1 extends Application {      // launch the application    public void start(Stage stage)    {          try {              // set title for the stage            stage.setTitle("Split Pane");              // create a splitpane            SplitPane split_pane = new SplitPane();              // create labels and add it to splitPane            for (int i = 1; i < 5; i++) {                  split_pane.getItems().add(new Label("\tLabel no "                                                     + i + "\t"));            }              // create a scene            Scene scene = new Scene(split_pane, 500, 300);              // set the scene            stage.setScene(scene);              stage.show();        }          catch (Exception e) {              System.out.println(e.getMessage());        }    }      // Main Method    public static void main(String args[])    {          // launch the application        launch(args);    }}Output:Java program to create a split pane set its orientation and add labels to it:In this program we will create a SplitPane name split_pane.Create and add labels to the split pane using getItems().add() function.Add the split_pane to the scene and add the scene to the stage.Set the orientation of the split_pane using the setOrientation() function.Call the show() function to display the final results.// Java program to create a split pane, set// its orientation and add labels to itimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.scene.layout.*;import javafx.scene.paint.*;import javafx.scene.text.*;import javafx.geometry.*;import javafx.scene.layout.*;import javafx.scene.shape.*;import javafx.scene.paint.*;import javafx.scene.*;import java.io.*;import javafx.scene.image.*;  public class SplitPane_2 extends Application {      // launch the application    public void start(Stage stage)    {          try {              // set title for the stage            stage.setTitle("Split Pane");              // create a splitpane            SplitPane split_pane = new SplitPane();              // create labels and add it to splitPane            for (int i = 1; i < 5; i++) {                  // create a label                Label label = new Label("\tLabel no " + i + "\t");                  // set preferred height                label.setPrefHeight(50);                  split_pane.getItems().add(label);            }              // set Orientation of splitpane            split_pane.setOrientation(Orientation.VERTICAL);              // create a scene            Scene scene = new Scene(split_pane, 500, 300);              // set the scene            stage.setScene(scene);              stage.show();        }          catch (Exception e) {              System.out.println(e.getMessage());        }    }      // Main Method    public static void main(String args[])    {          // launch the application        launch(args);    }}Output:
Java program to create a split pane and add labels to it:In this program, we will create a SplitPane name split_pane.Create and add labels to the split pane using getItems().add() function.Add the split_pane to the scene and add the scene to the stage.Call the show() function to display the final results.// Java program to create a split pane// and add labels to itimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.scene.layout.*;import javafx.scene.paint.*;import javafx.scene.text.*;import javafx.geometry.*;import javafx.scene.layout.*;import javafx.scene.shape.*;import javafx.scene.paint.*;import javafx.scene.*;import java.io.*;import javafx.scene.image.*;  public class SplitPane_1 extends Application {      // launch the application    public void start(Stage stage)    {          try {              // set title for the stage            stage.setTitle("Split Pane");              // create a splitpane            SplitPane split_pane = new SplitPane();              // create labels and add it to splitPane            for (int i = 1; i < 5; i++) {                  split_pane.getItems().add(new Label("\tLabel no "                                                     + i + "\t"));            }              // create a scene            Scene scene = new Scene(split_pane, 500, 300);              // set the scene            stage.setScene(scene);              stage.show();        }          catch (Exception e) {              System.out.println(e.getMessage());        }    }      // Main Method    public static void main(String args[])    {          // launch the application        launch(args);    }}Output:
In this program, we will create a SplitPane name split_pane.
Create and add labels to the split pane using getItems().add() function.
Add the split_pane to the scene and add the scene to the stage.
Call the show() function to display the final results.
// Java program to create a split pane// and add labels to itimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.scene.layout.*;import javafx.scene.paint.*;import javafx.scene.text.*;import javafx.geometry.*;import javafx.scene.layout.*;import javafx.scene.shape.*;import javafx.scene.paint.*;import javafx.scene.*;import java.io.*;import javafx.scene.image.*;  public class SplitPane_1 extends Application {      // launch the application    public void start(Stage stage)    {          try {              // set title for the stage            stage.setTitle("Split Pane");              // create a splitpane            SplitPane split_pane = new SplitPane();              // create labels and add it to splitPane            for (int i = 1; i < 5; i++) {                  split_pane.getItems().add(new Label("\tLabel no "                                                     + i + "\t"));            }              // create a scene            Scene scene = new Scene(split_pane, 500, 300);              // set the scene            stage.setScene(scene);              stage.show();        }          catch (Exception e) {              System.out.println(e.getMessage());        }    }      // Main Method    public static void main(String args[])    {          // launch the application        launch(args);    }}
Output:
Java program to create a split pane set its orientation and add labels to it:In this program we will create a SplitPane name split_pane.Create and add labels to the split pane using getItems().add() function.Add the split_pane to the scene and add the scene to the stage.Set the orientation of the split_pane using the setOrientation() function.Call the show() function to display the final results.// Java program to create a split pane, set// its orientation and add labels to itimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.scene.layout.*;import javafx.scene.paint.*;import javafx.scene.text.*;import javafx.geometry.*;import javafx.scene.layout.*;import javafx.scene.shape.*;import javafx.scene.paint.*;import javafx.scene.*;import java.io.*;import javafx.scene.image.*;  public class SplitPane_2 extends Application {      // launch the application    public void start(Stage stage)    {          try {              // set title for the stage            stage.setTitle("Split Pane");              // create a splitpane            SplitPane split_pane = new SplitPane();              // create labels and add it to splitPane            for (int i = 1; i < 5; i++) {                  // create a label                Label label = new Label("\tLabel no " + i + "\t");                  // set preferred height                label.setPrefHeight(50);                  split_pane.getItems().add(label);            }              // set Orientation of splitpane            split_pane.setOrientation(Orientation.VERTICAL);              // create a scene            Scene scene = new Scene(split_pane, 500, 300);              // set the scene            stage.setScene(scene);              stage.show();        }          catch (Exception e) {              System.out.println(e.getMessage());        }    }      // Main Method    public static void main(String args[])    {          // launch the application        launch(args);    }}Output:
In this program we will create a SplitPane name split_pane.
Create and add labels to the split pane using getItems().add() function.
Add the split_pane to the scene and add the scene to the stage.
Set the orientation of the split_pane using the setOrientation() function.
Call the show() function to display the final results.
// Java program to create a split pane, set// its orientation and add labels to itimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.scene.layout.*;import javafx.scene.paint.*;import javafx.scene.text.*;import javafx.geometry.*;import javafx.scene.layout.*;import javafx.scene.shape.*;import javafx.scene.paint.*;import javafx.scene.*;import java.io.*;import javafx.scene.image.*;  public class SplitPane_2 extends Application {      // launch the application    public void start(Stage stage)    {          try {              // set title for the stage            stage.setTitle("Split Pane");              // create a splitpane            SplitPane split_pane = new SplitPane();              // create labels and add it to splitPane            for (int i = 1; i < 5; i++) {                  // create a label                Label label = new Label("\tLabel no " + i + "\t");                  // set preferred height                label.setPrefHeight(50);                  split_pane.getItems().add(label);            }              // set Orientation of splitpane            split_pane.setOrientation(Orientation.VERTICAL);              // create a scene            Scene scene = new Scene(split_pane, 500, 300);              // set the scene            stage.setScene(scene);              stage.show();        }          catch (Exception e) {              System.out.println(e.getMessage());        }    }      // Main Method    public static void main(String args[])    {          // launch the application        launch(args);    }}
Output:
Note: The above programs might not run in an online IDE please use an offline compiler.
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/SplitPane.html
JavaFX
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
HashMap in Java with Examples
Interfaces in Java
Object Oriented Programming (OOPs) Concept in Java
How to iterate any Map in Java
Initialize an ArrayList in Java
Singleton Class in Java
Overriding in Java
Collections in Java
Multithreading in Java
Set in Java