Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing images to fit the parent node

How do I get an image in an ImageView to automatically resize such that it always fits the parent node?

Here is a small code example:

@Override public void start(Stage stage) throws Exception {     BorderPane pane = new BorderPane();     ImageView img = new ImageView("http://...");      //didn't work for me:     //img.fitWidthProperty().bind(new SimpleDoubleProperty(stage.getWidth()));       pane.setCenter(img);      Scene scene = new Scene(pane);     stage.setScene(scene);     stage.show(); } 
like image 261
rbs Avatar asked Sep 27 '12 21:09

rbs


1 Answers

@Override public void start(Stage stage) throws Exception {     BorderPane pane = new BorderPane();     ImageView img = new ImageView("http://...");      img.fitWidthProperty().bind(stage.widthProperty());       pane.setCenter(img);      Scene scene = new Scene(pane);     stage.setScene(scene);     stage.show(); } 
like image 111
The Unfun Cat Avatar answered Sep 28 '22 00:09

The Unfun Cat