Adding components to StackPane : StackPane « JavaFX « Java






Adding components to StackPane

 
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

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

  @Override
  public void start(Stage primaryStage) {
    primaryStage.setTitle("BorderPane Test");
    
    //Creating StackPane
    StackPane sp = new StackPane();
   
    //
    Label lbl = new Label("JavaFX 2 StackPane");
    sp.getChildren().add(lbl);
    Button btn = new Button("Button");
    sp.getChildren().add(btn);
   
    //Adding StackPane to the scene
    Scene scene = new Scene(sp,300,200);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
}

   
  








Related examples in the same category

1.Add Control to StackPane
2.Add StackPane to a Scene and then add Scene to Stage
3.StackPane based wizard
4.Using StackPane to hold controls
5.Align the title Label at the bottom-center of the stackpane
6.Create an 8 pixel margin around a listview in the stackpane