How do I make JavaFX MediaView stretch and shrink media to fill/fit parent container?
There's already a question here:
How do I make JavaFX MediaView stretch media to fill parent container?
and the solution with this code:
<Pane fx:id="mediaViewPane">
<children>
<MediaView fx:id="videoView" fitHeight="${mediaViewPane.height}" fitWidth="${mediaViewPane.width}" layoutX="1.0" />
</children>
</Pane>
works for making the video bigger to fill the container, but it doesn't allow the container to be smaller than the size of the video, so, it doesn't shrink, it just starts hiding controls as they fall outside the scene.
Any ideas how to stretch but also shrink the MediaView to fit?
I have achieved this, although I'm not super confident about this being the best approach. First, as fabian pointed out, I need to set the
MediaViewas not managed so that the parentPanecan be resized to any size without theMediaViewconstraining it:Then, on a rezise event, I resize the
MediaViewto fit in the parent, then get the actual size of the video and offset it to center: