JavaFX ImageView set fit height/width

Description

JavaFX ImageView set fit height/width

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class Main extends Application {
  @Override/*from   w w  w .  j  a v  a 2  s.co  m*/
  public void start(Stage primaryStage) {
    // Create a pane to hold the image views
    Pane pane = new HBox(10);
    pane.setPadding(new Insets(5, 5, 5, 5));
    Image image = new Image("icon.png");
    ImageView imageView = new ImageView(image);
    imageView.setFitHeight(100);
    imageView.setFitWidth(100);
    pane.getChildren().add(imageView);  
        

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

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



PreviousNext

Related