0

I have a JavaFX BorderPane in which I add an ImageView as the center node of the BorderPane. The ImageView becomes very big, and overlapsed other nodes.

I want to set the dimensions of the ImageView programmatically for the case that the user resizes the window, so I thought I can use Bindings.

public class MainController implements FxController {
    private ImageView videoImageView;

    @FXML
    BorderPane borderPane;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        this.videoImageView = new ImageView();
        this.videoImageView.setPreserveRatio(true);

        videoImageView.fitWidthProperty().bind(borderPane.widthProperty());
        videoImageView.fitHeightProperty().bind(borderPane.heightProperty());

        borderPane.setCenter(videoImageView);
    }

}

Screenshot of the programm

The problem is that the used properties deliver the full width and height of the whole BorderPane. How can I assign the whole available space of the center node to the ImageView and how can the ImageView be responsive using Bindings?

kanka.dev
  • 57
  • 7
  • 2
    I don’t know that you need bindings here. It would appear that all you want is a [resizable ImageView](https://stackoverflow.com/questions/22993550/how-to-resize-an-image-when-resizing-the-window-in-javafx). Let the layout (the BorderPane) run the size calculations, that’s what it is for. – jewelsea May 29 '22 at 23:25
  • Also see Region image background sizing attributes for CSS in the CSS reference guide for an alternative approach. – jewelsea May 29 '22 at 23:27
  • Thanks. I deleted all related bindings and used a wrapper class for the ImageView which is handling the size. – kanka.dev May 31 '22 at 13:03

0 Answers0