JDK-8090000 : [JFXPanel] scene doesn't gain focus when node programatically focused
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2015-05-05
  • Updated: 2018-09-06
  • Resolved: 2017-08-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Relates :  
Description
When requesting focus to a javafx node which is inside a JFXPanel when the jfxpanel is not the focus owner of the Swing Focus Manager, the JFXPanel is not focused. This cause the javafx node to presented as is didn't receive the focus even when the node is marked as the focus owner in the scene.

Example:
1. Press the swing button
The text field is not presented as focused.

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;

public class SampleFocusApp extends JFrame
{
  private TextField textField;

  public SampleFocusApp()
  {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    final JFXPanel panel = new JFXPanel();
    panel.setPreferredSize(new Dimension(200, 200));
    add(panel, BorderLayout.CENTER);
    JButton button = new JButton("Button");
    button.addActionListener(e -> Platform.runLater(() -> textField.requestFocus()));

    add(button, BorderLayout.SOUTH);

    Platform.runLater(() -> {
      textField = new TextField("Text");
      VBox root = new VBox(new Button("FX Button"), textField);
      final Scene scene = new Scene(root);
      panel.setScene(scene);

      scene.focusOwnerProperty().addListener((InvalidationListener) observable -> {
        System.out.println(scene.getFocusOwner());
      } );

      SwingUtilities.invokeLater(() -> {
        button.requestFocusInWindow();
      } );
    } );
    pack();
  }

  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(() -> (new SampleFocusApp()).setVisible(true));
  }

}





Comments
Node.requestFocus() says ----- If this node is eligible, this function will cause it to become this * {@code Scene}'s "focus owner". Each scene has at most one focus owner * node. The focus owner will not actually have the input focus, however, * unless the scene belongs to a {@code Stage} that is both visible * and active. ---------- So when we press swing button (which is supposed to transfer the focus to fx textfield), it makes the textfield "focus owner" which can be verified from the println log to show who is the focusowner TextField@5f46ff77[styleClass=text-input text-field]. Now, since the scene is not active now (swing is the active), it does not get the input focus. If we click on anywhere in fx scene, then the textfield gets the input focus (and not to fx button to show textfield is the focus owner.)
14-08-2017

This may be related to other JFXPanel focus bugs such as RT-39623
05-05-2015