JavaFX Separator

Jakob Jenkov
Last update: 2019-07-24

The JavaFX Separator component shows a visual divider between groups of components - e.g. between groups of controls inside a JavaFX VBox or JavaFX VBox. The JavaFX Separator is represented by the class javafx.scene.control.Separator. Here is a screenshot of a JavaFX application containing a VBox with a Label, a Separator and a Label:

JavaFX Separator screenshot.

Full JavaFX Separator Example

Here is a full JavaFX Separator example to give you an idea about how using it looks in code:

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SeparatorExample extends Application {

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

  public void start(Stage primaryStage) {

    Label label1 = new Label("Component 1");
    Label label2 = new Label("Component 2");

    Separator separator = 
new Separator(Orientation.HORIZONTAL); VBox vBox = new VBox(label1, separator, label2); Scene scene = new Scene(vBox); primaryStage.setScene(scene); primaryStage.setTitle("JavaFX App"); primaryStage.show(); } }

Notice how the Separator is passed as second parameter to the VBox component, between the first and second Label.

Separator Orientation

You can specify whether the JavaFX Separator is supposed to be vertical or horizontal. You do so by passing a parameter to the Separator constructor. Here are two examples that set the orientation of the Separator created to horizontal and vertical:

Separator separator = 
new Separator(Orientation.HORIZONTAL); Separator separator =
new Separator(Orientation.VERTICAL);

Jakob Jenkov

Featured Videos

Java Generics

Java ForkJoinPool

P2P Networks Introduction



















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next