Friday, May 27, 2016

13. StackPane

Two circles, with different radius and color, are drawn using StackPane layout.


The default alignment is center of parent.


package ex13;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Ex13 extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        
        StackPane root = new StackPane();
        
        Circle circ1 = new Circle(100, 100, 50, Color.RED);
        Circle circ2 = new Circle(200, 200, 25, Color.BLUE);
        root.getChildren().addAll(circ1, circ2);
        
        Scene scene = new Scene(root, 400, 400, Color.HONEYDEW);
        
        primaryStage.setTitle("Example 13. StackPane");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

This is the output:


No comments:

Post a Comment