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

Sub Menu Fails to show when ContextMenu is rebuilt by clearing and re-adding MenuItems

    Details

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

      Java 8u-dev repo tip, Linux

      Description

      I believe a recent fix has caused sub menus to fail to show in ContextMenus.

      To reproduce run the test class below:

      1. Right cick on the label and mouse over the sub menu to display it.

      2. Click on the Rebuild button.

      3. Repeat step 1.

      ********************************************* Test Class **********************************************
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.Label;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuItem;
      import javafx.scene.layout.Region;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ContextMenuTest extends Application {

         @Override public void start(final Stage primaryStage) throws Exception {

            primaryStage.centerOnScreen();
            primaryStage.setHeight(350);
            primaryStage.setWidth(500);
            final Menu submenu = new Menu("Sub Menu");
            submenu.getItems().add(new MenuItem("Test 1"));
              
            Label contextMenuLabel = new Label("Right Click On Me!");
            final ContextMenu contextMenu = new ContextMenu(submenu);
            contextMenuLabel.setContextMenu(contextMenu);
             
            Button button = new Button("Rebuild Menu");
            button.setOnAction(new EventHandler<ActionEvent>() {
               @Override public void handle(ActionEvent event) {
                  contextMenu.getItems().clear();
                  contextMenu.getItems().add(submenu);
               }
            });
            VBox box = new VBox(20, contextMenuLabel, button);
            box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
             
            primaryStage.setScene( new Scene( new StackPane( box ) ) );

            primaryStage.show();

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

      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jgiles Jonathan Giles
                Reporter:
                csmithjfx Charles Smith (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: