Pesquisar neste blog

04/05/2020

Layout em Java

EXEMPLO 1:

package visao;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class LayoutStackPane extends Application{
    @Override
    public void start(Stage primary){
        StackPane stackPane = new StackPane();
        stackPane.setPadding(new Insets(20));
        Rectangle r1 = new Rectangle(300, 300);
        r1.setFill(Color.RED);
        Rectangle r2 = new Rectangle(200, 200);
        r2.setFill(Color.BLUE);
        Rectangle r3 = new Rectangle(100, 100);
        r3.setFill(Color.AQUA);
        Rectangle r4 = new Rectangle(50, 50);
        r4.setFill(Color.BROWN);
        stackPane.getChildren().addAll(r1, r2, r3, r4);
        
        Scene cena = new Scene(stackPane);
        primary.setScene(cena);
        primary.setTitle("Gerenciador de Layout StackPane");
        primary.show();
    }
    public static void main(String[] args) {
        LayoutStackPane.launch(args);
    }
    
}



EXEMPLO 2:

package visao;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class LayoutVBox extends Application{
    @Override
    public void start(Stage primaryStage) throws Exception{
        
        VBox vbox = new VBox(10);
        vbox.setPadding(new Insets(20));
        Rectangle r1 = new Rectangle(50, 50);
        Rectangle r2 = new Rectangle(100, 100);
        Rectangle r3 = new Rectangle(25, 100);
        Rectangle r4 = new Rectangle(250, 50);
        VBox.setMargin(r1, new Insets(10, 10, 10, 10));
        vbox.getChildren().addAll(r1, r2, r3, r4);

        Scene cena = new Scene(vbox);
        primaryStage.setScene(cena);
        primaryStage.setTitle("Gerenciador de Layout VBox");
        primaryStage.show();
    }
    
    public static void main(String[] args) {
        LayoutVBox.launch(args);
    }   
}

EXEMPLO 3:

package visao;
import javafx.geometry.Insets;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class LayoutHBox extends Application{
    @Override
    public void start(Stage Henrique){
        HBox hbox = new HBox(15);
        hbox.setPadding(new Insets(20));
        Rectangle r1 = new Rectangle(100, 100);
        Rectangle r2 = new Rectangle(200, 200);
        Rectangle r3 = new Rectangle(50, 200);
        Rectangle r4 = new Rectangle(200, 50);
        HBox.setMargin(r1, new Insets(10, 10, 10, 10));
        hbox.getChildren().addAll(r1, r2, r3, r4);
        
        Scene cena = new Scene(hbox);
        Henrique.setScene(cena);
        Henrique.setTitle("Gerenciador de Layout HBox");
        Henrique.show();
    }
    
    public static void main(String[] args) {
        LayoutHBox.launch(args);
    }
}


EXEMPLO 4:

package visao;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class LayoutFlowPane extends Application{
    @Override
    public void start(Stage primaryKey){
        FlowPane flowPane = new FlowPane(Orientation.VERTICAL);//fluxo de distribuição
        flowPane.setAlignment(Pos.TOP_LEFT);
        flowPane.setPadding(new Insets(20));
        Rectangle r1 = new Rectangle(50, 50);//quadrado 1
        r1.setFill(Color.RED);
        Rectangle r2 = new Rectangle(150, 60);//retangulo vertical
        r2.setFill(Color.BLUE);
        Rectangle r3 = new Rectangle(250, 50);
        r3.setFill(Color.AQUA);
        Rectangle r4 = new Rectangle(250, 50);
        FlowPane.setMargin(r1, new Insets(10, 10, 10, 10));
        flowPane.getChildren().addAll(r1, r2, r3, r4);
        
        Scene cena = new Scene(flowPane);
        primaryKey.setScene(cena);
        primaryKey.setTitle("Gerenciador de Layout FlowPane");
        primaryKey.show();
    }
    public static void main(String[] args) {
        LayoutFlowPane.launch(args);
    }
}

Nenhum comentário: