JavaFX Tutorial - Java ToolBar() Constructor








Syntax

ToolBar() constructor from ToolBar has the following syntax.

public ToolBar()

Example

In the following code shows how to use ToolBar.ToolBar() constructor.

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Separator;
import javafx.scene.control.ToolBar;
import javafx.stage.Stage;
/*from w w  w . j a  v a2s. c  o m*/
public class Main extends Application {
  public static void main(String[] args) {
    launch(args);
  }
  @Override
  public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);
    stage.setHeight(150);

    ToolBar toolBar = new ToolBar();
    toolBar.getItems().add(new Button("New"));
    toolBar.getItems().add(new Button("Open"));
    toolBar.getItems().add(new Button("Save"));
    toolBar.getItems().add(new Separator());
    toolBar.getItems().add(new Button("Clean"));
    toolBar.getItems().add(new Button("Compile"));
    toolBar.getItems().add(new Button("Run"));
    toolBar.getItems().add(new Separator());
    toolBar.getItems().add(new Button("Debug"));
    toolBar.getItems().add(new Button("Profile"));
    toolBar.setOrientation(Orientation.HORIZONTAL);

    System.out.println(toolBar.orientationProperty());
    ((Group) scene.getRoot()).getChildren().add(toolBar);

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