我试图将JavaFx VBox节点嵌入到Swing JFrame中,但是在Swane带有BorderLayout的JPane中,VBox不会自动调整大小。如何使用BorderLayout作为其内容窗格的布局来绑定JFXPanel宽度以相对于父JFrame调整大小?
代码:
public JFXPanel createMyPaneScene(JFXPanel fxPanel) {
Group root=new Group();
Scene scene=new Scene(root,Color.ALICEBLUE);
VBox tp=createControlsParent();
root.getChildren().add(tp);
fxPanel.setScene(scene);
return fxPanel;
}
public VBox createControlsParent() {
VBox buttonsContainer = new VBox();
//Other JavaFx code
}
public MyApp() {
JFrame frame=new JFrame("My App");
frame.setBounds(100, 100, 730, 500);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JPane contentPane=new JPanel(new BorderLayout());
//other code
JFXPanel ctrlPane=this.createMyPaneScene(new JFXPanel());
contentPane.add(ctrlPane,BorderLayout.SOUTH);
frame.setContentPane(contentPane);
frame.setVisible(true);
}
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MyApp();
}
});
}