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

JavaFX modal dialog does not block events in SWT applications

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      I embedded a JavaFX button in a SWT application using FXCanvas. When the JavaFX button is pressed a modal JavaFX dialog appears.
      - if I click on any SWT UI the SWT window is shown on top of the dialog
      - if I press a SWT button the events a cashed and performed as soon as I closed the dialog

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - start the sample application
      - press the JavaFX button to show the modal dialog
      - click on the SWT button
      - close the dialog

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      - the dialog should remain on top
      - the click on the SWT button should be ignored
      ACTUAL -
      - the dialog is behind the SWT window
      - the clicks are performed as soon as the dialog has been closed

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.embed.swt.FXCanvas;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Alert;
      import javafx.scene.control.Button;
      import org.eclipse.swt.SWT;
      import org.eclipse.swt.graphics.Point;
      import org.eclipse.swt.layout.RowLayout;
      import org.eclipse.swt.widgets.Display;
      import org.eclipse.swt.widgets.Shell;

      public class JavaFxInSwtModalDialogBug {

        public static void main(String[] args) {
          Display display = new Display();
          Shell shell = new Shell(display);
          shell.setLayout(new RowLayout());
       
          org.eclipse.swt.widgets.Button swtButton = new org.eclipse.swt.widgets.Button(shell, SWT.PUSH);
          swtButton.setText("SWT Button");

          FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE) {
            @Override
            public Point computeSize(int wHint, int hHint, boolean changed) {
              getScene().getWindow().sizeToScene();
              int width = (int) getScene().getWidth();
              int height = (int) getScene().getHeight();
              return new Point(width, height);
            }
          };

          Button jfxButton = new Button("JFX Button");
          fxCanvas.setScene(new Scene(new Group(jfxButton)));
       
          swtButton.addListener(SWT.Selection, event -> System.out.println("SWT has been clicked!"));
          jfxButton.setOnAction(event -> new Alert(Alert.AlertType.INFORMATION).showAndWait());

          shell.open();
          while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
              display.sleep();
            }
          }
          display.dispose();
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use a SWT dialog instead.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: