Java 为什么我有网格窗格调整问题?

Java 为什么我有网格窗格调整问题?,java,javafx,Java,Javafx,在网格窗格中添加MediaView后。一切正常 但是,更改窗口大小后,MediaView的大小将不会调整 在最大化窗口后,MediaView会变大,这很好,但在进行窗口还原之后,MediaView不会变小 当前代码: import java.io.File; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.beans.property.DoubleProperty

网格窗格中添加
MediaView
后。一切正常

但是,更改窗口大小后,
MediaView
的大小将不会调整

在最大化窗口后,
MediaView
会变大,这很好,但在进行窗口还原之后,
MediaView
不会变小

当前代码:

import java.io.File;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class MWindow extends Application {
    @Override
    public void start(Stage primaryStage) {

        GridPane GB = new GridPane();
        GB.setHgap(10);
        GB.setVgap(10);
        GB.setPadding(new Insets(0, 10, 0, 10));
        ColumnConstraints col1 = new ColumnConstraints();
        col1.setPercentWidth(50);

        ColumnConstraints col2 = new ColumnConstraints();
        col2.setHgrow(Priority.ALWAYS);

        GB.setStyle("-fx-border: 2px solid; -fx-border-color: red;");

        GB.getColumnConstraints().addAll(col1, col2);

        StackPane stack = new StackPane();
        StackPane stack1 = new StackPane();

        File f = new File("C:\\Users\\anaskar\\Desktop\\bisquad\\UserManual\\Demo.mp4");

        Media m = new Media(f.toURI().toString());
        MediaPlayer mp = new MediaPlayer(m);
        MediaView mv = new MediaView(mp);

        DoubleProperty width = mv.fitWidthProperty();
        DoubleProperty height = mv.fitHeightProperty();

        width.bind(Bindings.selectDouble(mv.parentProperty(), "width"));
        height.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));

        mv.setPreserveRatio(true);

        Media m1 = new Media(f.toURI().toString());
        MediaPlayer mp1 = new MediaPlayer(m1);
        MediaView mv1 = new MediaView(mp1);

        DoubleProperty width1 = mv1.fitWidthProperty();
        DoubleProperty height1 = mv1.fitHeightProperty();

        width1.bind(Bindings.selectDouble(mv1.parentProperty(), "width"));
        height1.bind(Bindings.selectDouble(mv1.sceneProperty(), "height"));

        stack.getChildren().add(mv);
        stack1.getChildren().add(mv1);

        Scene scene = new Scene(GB, 960, 540);
        scene.setFill(Color.BLACK);

        GB.add(stack, 0, 0, 1, 1);
        GB.add(stack1, 1, 0, 1, 1);

        primaryStage.setScene(scene);
        primaryStage.setTitle("Full Screen Video Player");
        primaryStage.show();

        mp.play();
        mp1.play();

    }

    public static void main(String[] args) {
        launch(args);
    }
}

您必须为包含
MediaView

  StackPane stack = new StackPane();
  stack.setMinSize(50, 50);
  StackPane stack1 = new StackPane();
  stack1.setMinSize(50, 50);