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

Event is not consumed in Tab.setOnCloseRequest()

    XMLWordPrintable

Details

    • x86_64
    • generic

    Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      Consider the following program:

          public class MainClass extends Application {
          
              public static void main(String[] arg) {
                  launch(arg);
              }
          
              @Override
              public void start(Stage primaryStage) throws Exception {
                  TabPane tabPane = new TabPane();
                  tabPane.getSelectionModel().selectedItemProperty().addListener((ov, oldTab, newTab) -> {
                      System.out.println("Tab change: " + oldTab + "/" + newTab);
                  });
                  Tab tab = new Tab("Test tab");
                  tab.setOnCloseRequest((event) -> {
                      System.out.println("Removing tab");
                      event.consume();
                      tabPane.getTabs().remove(tab);
                  });
                  System.out.println("Adding tab");
                  tabPane.getTabs().add(tab);
                  Group root = new Group(tabPane);
                  Scene scene = new Scene(root);
                  primaryStage.setScene(scene);
                  primaryStage.show();
              }
          
          }

      When this program is executed and user clicks close icon on Tab, then the total output of the program is:

          Adding tab
          Tab change: null/javafx.scene.control.Tab@70b1aa69
          Removing tab
          Tab change: javafx.scene.control.Tab@70b1aa69/null
          Tab change: null/javafx.scene.control.Tab@70b1aa69

      As you see there are two `Tab change` events after removing tab but there must be only one.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      Attachments

        Activity

          People

            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: