package testjavafx; import java.awt.BorderLayout; import javafx.application.Application; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.web.HTMLEditor; import javafx.stage.Stage; import javax.swing.JFrame; import javax.swing.SwingUtilities; /** * * @author scott */ public class FxMain extends Application { static boolean useJFXPanel = true; // change this to see different behavior static String title = "JavaFX UI Test - HTMLEditor eats Enter key in JFXPanel"; /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { if (useJFXPanel) { launchWithJFXPanel(); } else { launch(args); } } @Override public void start(Stage primaryStage) { primaryStage.setTitle(title); primaryStage.setScene(new Scene(createRoot())); primaryStage.show(); } ////// JFXPanel >>>>>> static void launchWithJFXPanel() throws Exception { final JFXPanel jfxpanel = new JFXPanel(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { initSwing(jfxpanel); } }); Platform.runLater(new Runnable() { public void run() { jfxpanel.setScene(new Scene(createRoot())); } }); } private static void initSwing(JFXPanel jfxpanel) { JFrame frame = new JFrame(title); frame.getContentPane().add(jfxpanel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 240); frame.setVisible(true); } ////// <<< JFXPanel static Parent createRoot() { HTMLEditor root = new HTMLEditor(); return root; } }