How do I make JavaFX MediaView stretch media to fill parent container?

前端 未结 4 1030
故里飘歌
故里飘歌 2020-12-17 20:38

I\'m trying to make my video\'s dimensions stretch automatically and fill the MediaView and maintain the original aspect ratio of the video. Basically, I want my MediaPlayer

4条回答
  •  离开以前
    2020-12-17 21:16

    A more declarative way in a ".fxml" file would be:

    ...
    
      
         
      
    
    ...
    

    You can use the "${...}" syntax for any attribute in your ".fxml" for Expression Binding. If you want to call a UI element you have to provide a "fx:id". For example in this case it's fx:id="mediaViewPane".

    So you don't have to care about the UI stuff in your code. For me it's a little bit cleaner.

提交回复
热议问题