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

CustomMenuItem in a sub menu will fire once for each time the sub men has been shown.

    XMLWordPrintable

    Details

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

      Java 8u-dev repo tip, Linux

      Description

      I have a CustomMenuItem that seems to fire multiple times when it is clicked. I have tracked this down and made the following test class to reproduce the bug.

      1. Run the provided test class

      2. Use the Top Menu to display the sub menu and click on the "Testing" menu item.

      3. Repeat step 2 a couple times.

      You will notice the output in the log multiplies each time the menu has been displayed. It show one line the first time, then 2 lines, then 3, etc.

      Looks to me like this stems from the MenuItemContainer class. It adds an EventHandler to the CustomMenuItem's content node but it never removes it...

      ******************************************** Test Class ***************************************************
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.CustomMenuItem;
      import javafx.scene.control.Label;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class CustomMenuItemTest extends Application {

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

            primaryStage.centerOnScreen();
            primaryStage.setHeight(350);
            primaryStage.setWidth(500);
             
            CustomMenuItem item = new CustomMenuItem(new Label("Testing"));
            item.setOnAction(new EventHandler<ActionEvent>() {
               @Override public void handle(ActionEvent event) {
                  System.out.println("testing fired!");
               }
            });
            final Menu submenu = new Menu("Sub Menu");
            submenu.getItems().add(item);
            
            Menu topMenu = new Menu("Top Menu");
            topMenu.getItems().add(submenu);
            MenuBar menuBar = new MenuBar();
            menuBar.getMenus().add(topMenu);
            
            BorderPane pane = new BorderPane();
            pane.setTop(menuBar);
            
            primaryStage.setScene( new Scene( pane ) );

            primaryStage.show();

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

      }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: