JavaFX Separator Tutorial

JavaFX Separator :

  • The JavaFX Separator UI control is used to represent a horizontal or vertical separator line to divide elements.
  • It by default horizontal.
  • And it does not do any other action.

Constructors:

  • Separator()
    Creates a new horizontal separator with halignment and valignment set to their respective CENTER values.
  • Separator(Orientation orientation)

    Creates a new separator with halignment and valignment set to their respective CENTER values.

Creating a Separator :

Separator sp = new Separator();

Separator is by default horizontal so for vertical separator we use set Orientation() method AS

sp.setOrientation(Orientation.VERTICAL);

//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

(adsbygoogle = window.adsbygoogle || []).push({});

Example of separator :

 
package javafxtuts;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Javafxtuts extends Application {

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

  @Override
  public void start(Stage stage) {
      stage.setTitle("Javafxtuts.com");
      
      Label lb =new Label("Java");
      Label lb1 =new Label("JavaScript");
      Separator sep = new Separator();
      sep.setOrientation(Orientation.VERTICAL);
      sep.setMaxHeight(25);
      HBox root =new HBox();
      root.setPadding(new Insets(10, 10, 10, 10));
      root.setSpacing(5);
      root.getChildren().addAll(lb,sep,lb1);
        Scene scene = new Scene(root, 250, 200);
        stage.setScene(scene);
        stage.show();
  }
}

Output :


javafx separator,javafx separator tutorials

Explanation of separator example :

  • Creating a new Seprator AS
    Separator sep = new Separator();
  • make it vertical using setOrientation() method AS
    sep.setOrientation(Orientation.VERTICAL);
  • sep.setMaxHeight(25);
    Is used to set the maximum height of the separator.