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

JavaFX Menu and MenuBar not consistent with native menus

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.8.0_101"

      ADDITIONAL OS VERSION INFORMATION :
      Linux blue 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u2 (2016-06-25) x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Gnome Classic 3.14.1

      A DESCRIPTION OF THE PROBLEM :
      The JavaFX MenuBar has some visual and functional problems:

      • A MenuBar has a left margin of approximately ten pixels, to the left of its first Menu. Native menu bars do not have any such margin.
      • The MenuBar takes keyboard focus, and highlights its first Menu, as soon as Alt is pressed. This should happen only when Alt is pressed and released, with no intervening keystrokes (or when F10 is pressed and released). The current behavior is not only inconsistent with native menu bars, it can cause particularly strange behaviors when one uses Alt-Tab to switch focus to and from a JavaFX application.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run any JavaFX application with a MenuBar that has at least one non-empty Menu, and press Alt.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      MenuBars should look and behave like native menu bars: They should have no left margin; Menu headings should have equal left and right margins which match native menus; and the menu hierarchy should take focus when Alt is released, not when Alt is first pressed.
      ACTUAL -
      MenuBars do not look and behave like native menu bars: MenuBars have an extra left margin; Menus have an extra right margin; and the menu grabs focus as soon as Alt is pressed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.Label;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class MenuBarExample
      extends Application {
          @Override
          public void start(Stage stage) {
              MenuBar menuBar = new MenuBar(
                  new Menu("_File", null,
                      new MenuItem("_Open"),
                      new MenuItem("_Save"),
                      new MenuItem("E_xit")),
                  new Menu("_Edit", null,
                      new MenuItem("Cu_t"),
                      new MenuItem("_Copy"),
                      new MenuItem("_Paste")),
                  new Menu("_Help", null,
                      new MenuItem("Show _Help"),
                      new MenuItem("_About")));

              Label label = new Label("MenuBar Example");
              label.setPadding(new Insets(200));

              BorderPane pane = new BorderPane(label, menuBar, null, null, null);

              stage.setScene(new Scene(pane));
              stage.setTitle("MenuBar Example");
              stage.show();
          }
      }

      ---------- END SOURCE ----------

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

              Created:
              Updated: