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

MenuButton doesn't unhook it's MousePressed and MouseReleased listener on dispose

XMLWordPrintable

      Run this code and you will get an exception complaining that the behavior is null. This is because the old skin is still getting the mouse event after it has been disposed.

          @Override
          public void start(Stage stage) throws Exception {

              final MenuButton control = new MenuButton("Click Me!");
              control.getItems().addAll(new MenuItem("one"), new MenuItem("Two"));

              control.skinProperty().addListener((observable, oldValue, newValue) -> System.out.println("new skin: " + newValue.getClass().getName()));

              control.setSkin(new MenuButtonSkin(control) {});
              control.setSkin(new MenuButtonSkin(control));
              final VBox root = new VBox(control);

              Scene scene = new Scene(root, 400, 300);
              stage.setScene(scene);
              stage.show();
          }

            jgiles Jonathan Giles
            dgrieve David Grieve
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: