Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8088540

[SwingNode, JFXPanel] Focus issue when mixing JavaFX and Swing multiple times

XMLWordPrintable

      If I embed Swing into JavaFX which is embedded into Swing I do have issues with the focus of controls.



      Lets start with this example:

      public class EmbeddedTestWithFX extends JFrame {

          public EmbeddedTestWithFX() {
              setSize(new Dimension(300, 300));

              JTextArea textArea = new JTextArea();
              textArea.setSize(new Dimension(150, 150));

              JPanel container = new JPanel();
              container.setLayout(null);
              container.add(textArea);

              JFXPanel jfxPanel = new JFXPanel();

              Platform.runLater(() -> {
                  SwingNode swing = new SwingNode();
                  StackPane stack = new StackPane(swing);
                  Scene scene = new Scene(stack);
                  swing.setContent(container);
                  SwingUtilities.invokeLater(() -> jfxPanel.setScene(scene));
              });

              setContentPane(jfxPanel);
          }

          public static void main(String[] args) {
              new EmbeddedTestWithFX().setVisible(true);
          }
      }




      I can see the TextArea but the issue is, It doesn't get the focus by clicking on it (btw. it's the same for other controls like jButtons). If I register a FocusListener on the JTextArea, I see that it becomes the focus after a click, but it loses the focus instantly.

      But if I use:

      -Djavafx.embed.singleThread=true

      the example starts to work. I can click now the TextArea, it holds the focus and I can enter text.

            psadhukhan Prasanta Sadhukhan
            acasalljfx Alexander Casall (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: