import java.awt.BorderLayout; 
import javax.swing.SwingUtilities; 
import javax.swing.JPanel; 
import javax.swing.JFrame; 
import javafx.application.Platform; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.embed.swing.JFXPanel; 

/* 
 * Compile attached code saved as NonFocusableJFXPanel.java: 
 * 
 * javac NonFocusableJFXPanel.java 
 * 
 * Run it from a command prompt to see the messages printed by the Swing app: 
 * 
 * java -cp . NonFocusableJFXPanel 
 * 
 * Works fine with Java 1.8.0_162, Java 9.0.4 but not with Java 10. 
 */ 
public class NonFocusableJFXPanel { 
    public static void main(String[] args) { 
        SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                initAndShowGUI(); 
            } 
        }); 
    } 

    public static void initAndShowGUI() { 
        JFrame frame = new JFrame("NonFocusableJFXPanel"); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

        JPanel workArea = (JPanel) frame.getContentPane(); 

        final JFXPanel fxPanel = new JFXPanel(); 

        // With Java 10, works fine with .setFocusable(true). 
        fxPanel.setFocusable(false); 

        workArea.add(fxPanel, BorderLayout.CENTER); 

        Platform.runLater(new Runnable() { 
            public void run() { 
                initFX(fxPanel); 
            } 
        }); 

        frame.setSize(600, 200); 
        frame.setVisible(true); 
    } 

    private static int clickCount = 0; 

    private static void initFX(JFXPanel fxPanel) { 
        Button button = new Button("Click me ONCE and look at your console."); 
        button.setOnMousePressed(e -> System.err.println(++clickCount)); 

        Scene scene = new Scene(button); 
        fxPanel.setScene(scene); 
    } 
} 
