JavaFX GridPane hold ImageView

Description

JavaFX GridPane hold ImageView

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.geometry.Pos;

public class Main extends Application {
  @Override//from  w  ww .  j  a  v  a 2 s . c  o m
  public void start(Stage primaryStage) {
    GridPane pane = new GridPane();
    pane.setAlignment(Pos.CENTER);
    pane.setHgap(5);
    pane.setVgap(5);

    ImageView img1 = new ImageView(new Image("icon.png"));
    ImageView img2 = new ImageView(new Image("icon.png"));
    ImageView img3 = new ImageView(new Image("icon.png"));
    ImageView img4 = new ImageView(new Image("icon.png"));

    pane.addRow(0, img1, img2);
    pane.addRow(1, img3, img4);

    Scene scene = new Scene(pane);
    primaryStage.setTitle("java2s.com");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

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



PreviousNext

Related