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

Menu items that are shared by a menu and a context menu only work if they added to the context menu first

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux cay-Inspiron-7373 4.13.0-21-generic #24-Ubuntu SMP Mon Dec 18 17:29:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      When a menu item is shared between a regular menu and a context menu, it only shows up if you add it to the context menu first. When the order is reversed (adding the menu item to the menu, then the context menu), the item will fail to show up in the context menu.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the attached program.
      2. Right-click on the text area.
      3. Observe the menu says "Paste"
      4. Switch lines 23 and 24, compile and run.
      5. Right-click on the text area.
      6. Observe the menu says "Cut/Copy/Paste"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      In step 3, I expected to see the context menu with all three items.
      ACTUAL -
      In step 3, I saw the context menu only the item that wasn't shared..

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.*;
      import javafx.event.*;
      import javafx.scene.*;
      import javafx.scene.control.*;
      import javafx.scene.input.*;
      import javafx.scene.layout.*;
      import javafx.scene.text.*;
      import javafx.stage.*;

      public class MenuTest extends Application
      {
         private TextArea textArea = new TextArea();

         public void start(Stage stage)
         {

            MenuItem cutItem = new MenuItem("Cut");
            MenuItem copyItem = new MenuItem("Copy");
            MenuItem pasteItem = new MenuItem("Paste");
            MenuItem pasteItem2 = new MenuItem("Paste");

            // It works if you swap the following two lines.
            Menu editMenu = new Menu("Edit", null, cutItem, copyItem, pasteItem);
            ContextMenu contextMenu = new ContextMenu(cutItem, copyItem, pasteItem2);

            textArea.setContextMenu(contextMenu);
            MenuBar bar = new MenuBar(editMenu);
            VBox root = new VBox(bar, textArea);

            stage.setScene(new Scene(root));
            stage.show();
         }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      To populate the context menu first.

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

              Created:
              Updated: