在MediaView
内添加GridPane
后。一切都按预期工作。
但是,在更改窗口大小后,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);
}
}
答案 0 :(得分:0)
您必须为包含StackPane
MediaView
设置最小尺寸
StackPane stack = new StackPane();
stack.setMinSize(50, 50);
StackPane stack1 = new StackPane();
stack1.setMinSize(50, 50);