我已经使用了前面显示的代码How to run a javaFX MediaPlayer in swing?. 代码如下所示:
public class Test {
private static void initAndShowGUI() {
// This method is invoked on Swing thread
JFrame frame = new JFrame("FX");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setVisible(true);
Platform.runLater(new Runnable() {
@Override
public void run() {
initFX(fxPanel);
}
});
}
private static void initFX(JFXPanel fxPanel) {
// This method is invoked on JavaFX thread
Scene scene = createScene();
fxPanel.setScene(scene);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initAndShowGUI();
}
});
}
}
这对我有用,并允许在 JFXPanel 中显示媒体播放器。但是,当我调整 JFXPanel 的大小以使其适合我的屏幕时,播放器的大小也不一样。谁能回答这是怎么做到的?我认为它应该涉及绑定到 JFXpanel 但不确定如何实现。非常感谢帮助