【发布时间】:2016-12-13 23:50:55
【问题描述】:
我正在使用 JavaFX 8 中的 MultiMedia 类编写自己的多媒体应用程序。当我运行(开始)我的程序时,我希望我的 Stage 的宽度和高度与媒体的宽度和高度相同(视频)我想玩。
mp.setOnReady(new Runnable() {
@Override
public void run() {
Timeline slideIn = new Timeline();
Timeline slideOut = new Timeline();
stage.getScene().setOnMouseEntered(e -> {
slideIn.play();
});
stage.getScene().setOnMouseExited(e -> {
slideOut.play();
});
// here I get the width and heigth of the media
int w = mp.getMedia().getWidth();
int h = mp.getMedia().getHeight();
// width is 1280 and heigth is 720 (both values are correct)
if (w != 0 && h != 0) {
//Here Im setting the width and the height of stage
//But when I run my app, stage is a little bit smaller than
//MediaView and I have to resize the stage manually by cca 20px to get the whole view
stage.setWidth(w);
stage.setHeight(h);
stage.centerOnScreen();
//On the other hand, animation works pretty well and
//correctly with the "w" and "h"
mediaBar.setMinSize(w - 100, 100);
mediaBar.setTranslateY(h - 100);
mediaBar.setTranslateX(50);
mediaBar.setOpacity(0);
slideIn.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(mediaBar.translateYProperty(), h), new KeyValue(mediaBar.opacityProperty(), 0.0)),
new KeyFrame(new Duration(300), new KeyValue(mediaBar.translateYProperty(), h - 100), new KeyValue(mediaBar.opacityProperty(), 0.9))
);
slideOut.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(mediaBar.translateYProperty(), h - 100), new KeyValue(mediaBar.opacityProperty(), 0.9)),
new KeyFrame(new Duration(300), new KeyValue(mediaBar.translateYProperty(), h), new KeyValue(mediaBar.opacityProperty(), 0.0))
);
background.setWidth(w - 100);
background.setHeight(100);
background.setTranslateY(h - 100);
background.setTranslateX(50);
background.setOpacity(0);
slideIn.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(background.translateYProperty(), h), new KeyValue(background.opacityProperty(), 0.0)),
new KeyFrame(new Duration(300), new KeyValue(background.translateYProperty(), h - 100), new KeyValue(background.opacityProperty(), 1))
);
slideOut.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(background.translateYProperty(), h - 100), new KeyValue(background.opacityProperty(), 1)),
new KeyFrame(new Duration(300), new KeyValue(background.translateYProperty(), h), new KeyValue(background.opacityProperty(), 0.0))
);
} else {
//music
}
duration = mp.getMedia().getDuration();
updateValues();
}
});
所以我想,Stage 类有一些重要的东西我还不知道。
当我将initStyle 的Stage 设置为StageStyle.UNDECORATED 时,我可以看到整个MediaView。但我不想拥有这种风格。
谁能帮我解决这个问题?我希望我正确地描述了我的问题,因为这是我第一次寻求帮助。谢谢。
【问题讨论】:
标签: java javafx size stage multimedia