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

Active window can't be found if mixing Swing and JavaFX under javaws

XMLWordPrintable

    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version "1.8.0_65"
      Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OS X Yosemite - 10.10.5 (14F27)

      A DESCRIPTION OF THE PROBLEM :
      When mixing Swing and JavaFX code under Java Web Start, then unpredictable things can happen like you can't find the active window.

      deploy the attached source code to java web start, and execute the created jnlp and you will see, that when you click the swing button, it can find the active window, but when you click the JavaFX button, the active window is null.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      deploy the attached source code to java web start, and execute the created jnlp and you will see, that when you click the swing button, it can find the active window, but when you click the JavaFX button, the active window is null.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The javaws app can find the active window regardless of which button you press.
      ACTUAL -
      The javaws app can only find the active window when clicking on the swing button, and not when clicking JavaFX button.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.FlowLayout;
      import java.awt.KeyboardFocusManager;

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

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.HBox;

      public class TestMacWebStart {
      private static Button fxButton;
      private static JButton swingButton;
      public static void main(String[] args) {
      SwingUtilities.invokeLater(() -> {
      JFrame frame = new JFrame("Mac test");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel panel = new JPanel(new FlowLayout());
      JFXPanel fxpanel = new JFXPanel();
      Platform.runLater(() -> {
      fxButton = new Button("JavaFX button");
      fxButton.setOnAction(e -> {
      fxButton.setText("JavaFX button");
      SwingUtilities.invokeLater(() -> {
      System.out.println("active window in swing when clicking JavaFX button " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow());
      swingButton.setText("changed from JavaFX");
      });
      });
      fxButton.setMinWidth(180);
      fxpanel.setScene(new Scene(new HBox(fxButton)));
      });
      swingButton = new JButton("Swing button");
      swingButton.addActionListener(l -> {
      System.out.println("active window in swing when clicking swing button " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow());
      swingButton.setText("Swing button");
      Platform.runLater(() -> {
      fxButton.setText("changed from Swing");
      });
      });
      panel.add(fxpanel);
      panel.add(swingButton);
      frame.add(panel);
      frame.setSize(600, 600);
      frame.setVisible(true);
      });
      }
      }
      ---------- END SOURCE ----------

            alitvinov Anton Litvinov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: