How to resize an image when resizing the window in JavaFX

前端 未结 4 1485
-上瘾入骨i
-上瘾入骨i 2020-11-30 10:58

I want an image to be resized automatically when the user drags the main window. Is that possible?

I have the following code that sets a window of a certain size. It

4条回答
  •  悲&欢浪女
    2020-11-30 11:20

    I know this is old but someone like me may stumble upon this so here is my solution. I am assuming that root is the root node of your scene. However, this should work if your parent node of the ImageView is any child of Pane.

    imv = new ImageView();  
    root.getChildren().add(imv);
    Image image = new Image(Main.class.getResourceAsStream("image.png"))
    imv.setImage(image);
    
    imv.fitWidthProperty().bind(center.widthProperty());
    imv.fitHeightProperty().bind(center.heightProperty());
    

提交回复
热议问题