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

MenuBar does not lose focus after clicking a menu item

XMLWordPrintable

      Set up a simple menu bar and a simple textarea (or anything else that can receive focus).
      On a standard application one would expect that clicking some menu item such as File-->New will send the focus back to whatever had focus before, in this case, TextArea.
      However upon clicking New, the menu File remains highlighted, and the text area does not have focus.
      Please refer to the following code, which is also attached:


      import javafx.application.Application;
      import javafx.builders.*;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.control.TextArea;
      import javafx.stage.Stage;

      public class MenuFocusBugTest extends Application {

          @Override
          public void start(Stage stage) throws Exception {
              stage.setScene(
                      SceneBuilder.create()
                              .root(BorderPaneBuilder.create()
                                      .top(MenuBarBuilder.create()
                                              .menus(MenuBuilder.create()
                                                      .items(MenuItemBuilder.create()
                                                              .text("New")
                                                              .onAction(new EventHandler<ActionEvent>() {
                                                                  public void handle(ActionEvent actionEvent) {

                                                                  }
                                                              })
                                                              .build()
                                                      )
                                                      .text("File")
                                                      .build()
                                              )
                                              .build()
                                      )
                                      .center(
                                              new TextArea()
                                      )
                                      .build()
                              )
                              .build()
              );
              stage.setVisible(true);
          }

          public static void main(String[] args) {
              Application.launch(MenuFocusBugTest.class, null);
          }
      }

            miflemi Mick Fleming
            jforskyjfx Javic Forsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: