import java.awt.BorderLayout; import java.awt.Dimension; import java.beans.PropertyVetoException; import javax.swing.*; import javafx.application.*; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; public class SwingEmbedFX2 { protected static JFXPanel fxPanel; protected static JDesktopPane desktopPane; static void packInternalFrame(JInternalFrame iframe) { try { iframe.pack(); iframe.setIcon(true); iframe.setMaximum(true); iframe.moveToFront(); iframe.setVisible(true); // From setMaximum method call } catch (PropertyVetoException ex) { System.out.println(ex); ex.printStackTrace(); } } static void launchFXFrame() { JInternalFrame iframe = new JInternalFrame( "FX Embedded", true, true, true); iframe.setLayout(new BorderLayout()); desktopPane.add(iframe); try { iframe.setMaximum(true); // From setMaximum method call } catch (PropertyVetoException ex) { System.out.println(ex); ex.printStackTrace(); } fxPanel = new JFXPanel(); iframe.add(fxPanel, BorderLayout.CENTER); Platform.runLater(() -> createScene()); packInternalFrame(iframe); } public static void runTest() { final JFrame f = new JFrame(); f.setLayout(new BorderLayout()); f.setSize(new Dimension(500, 500)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); desktopPane = new JDesktopPane(); f.getContentPane().add(BorderLayout.CENTER, new JScrollPane(desktopPane)); JInternalFrame iframe = new JInternalFrame(); iframe.setResizable(true); JButton btn = new JButton("FX"); btn.addActionListener(a -> launchFXFrame()); iframe.add(btn); desktopPane.add(iframe); iframe.pack(); desktopPane.validate(); iframe.setVisible(true); desktopPane.setVisible(true); f.setVisible(true); } public static void createScene() { StackPane fxRoot = new StackPane(); fxPanel.setScene(new Scene(fxRoot)); BorderPane bp = new BorderPane(); fxRoot.getChildren().addAll(bp); bp.setCenter(new Label("FX Label")); } public static void main(String [] args) { try { SwingUtilities.invokeAndWait(() -> runTest()); } catch (Exception ex) { System.out.println(ex); ex.printStackTrace(); } } }