【发布时间】:2021-10-08 03:40:49
【问题描述】:
来自Integrating JavaFX 2.0 with Swing and SWT 的代码允许您在 Swing JFrame 中嵌入 JFXPanel。我想知道 JPanel 是否嵌入在 Application 或 Stage 中,这与 JFrame 中所指出的 Converting from Swing to JavaFX? 中的 JFrame 等价
/**
* Simple class demonstrating interoperability between Swing and JavaFX. This
* class is adapted from the example provided in the Javadoc documentation for
* {@code javafx.embed.swing.JFXPanel}.
*/
public class SwingJavaFxInteroperabilityDemo
{
private static void initAndShowGUI()
{
// This method is invoked on Swing thread
final JFrame frame = new JFrame("JavaFX / Swing Integrated");
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
final Scene scene = TextIntegrationSceneCreator.createTextScene();
fxPanel.setScene(scene);
}
public static void main(String[] arguments)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
initAndShowGUI();
}
});
}
}
【问题讨论】: