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

[Menu, Mac] Dynamic menus that open stages cause focus to be assigned to the parent stage

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
      None

      Description

      package application;

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.Event;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Modality;
      import javafx.stage.Stage;


      public class Main extends Application {
      @Override
      public void start(Stage primaryStage) {
      MenuBar bar = new MenuBar();
      Menu file = new Menu("File");

      MenuItem item = new MenuItem("Static Open Window");
      item.setOnAction(new EventHandler<ActionEvent>() {

      @Override
      public void handle(ActionEvent event) {
      openWindow(primaryStage);
      }
      });
      file.getItems().add(item);


      file.setOnShowing(new EventHandler<Event>() {

      @Override
      public void handle(Event event) {
      MenuItem item = new MenuItem("Dynamic Open Window");
      item.setOnAction(new EventHandler<ActionEvent>() {

      @Override
      public void handle(ActionEvent event) {
      openWindow(primaryStage);
      }
      });
      file.getItems().add(item);

      }
      });

      bar.getMenus().add(file);

      BorderPane p = new BorderPane();
      p.setTop(bar);
      p.setCenter(new TextField());

      primaryStage.setScene(new Scene(p,500,500));

      primaryStage.show();
      }

      private void openWindow(Stage primaryStage) {
      Stage s = new Stage();
      s.initModality(Modality.APPLICATION_MODAL);
      s.initOwner(primaryStage);
      s.setScene(new Scene(new BorderPane(new TextField()),200,200));
      s.showAndWait();
      }

      public static void main(String[] args) {
      launch(args);
      }
      }

      Run code:
      * click "Static Open Window" => type and input target is the new window text which is OK
      * close window
      * click one of the "Dynamic Open Window" => type and see that the input target is the old windows text field
      * close and notice that you can not reopen the menu (you can fix this by moving the focus out of the window and back in)

      This is a very serious bug for big applications (like Eclipse) who construct menus on demand

        Attachments

        1. c1.txt
          7 kB
        2. c2.txt
          7 kB
        3. glass.java
          4 kB
        4. rt-35401.patch
          2 kB

          Issue Links

            Activity

              People

              Assignee:
              msladecek Martin Sládeček
              Reporter:
              tschindl Tom Schindl
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: