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

Tab.setOnSelectionChanged fires twice even if nothing has changed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7u6
    • fx2.1
    • javafx

      Run the code.

      Click Tab2 once.
      Output: "Changed".
      All fine so far.
      ====================

      Then click on Tab2 again.
      Output: "Changed Changed"

      In the first event Tab2 is selected==false, then it is selected==true.
      So it seems a click on an already selected tab deselects it first, and then selects it again.

      There shouldn't be an event at all (nothing has changed, Tab2 was already selected), but instead TWO events are fired!



      import javafx.application.Application;
      import javafx.event.Event;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TestApp3 extends Application {

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

          public void start(final Stage stage) throws Exception {

              final VBox root = new VBox();

              TabPane tabPane = new TabPane();

              Tab tab1 = new Tab("Test1");
              Tab tab2 = new Tab("Test2");

              tabPane.getTabs().add(tab1);
              tabPane.getTabs().add(tab2);

              tab2.setOnSelectionChanged(new EventHandler<Event>() {
                  @Override
                  public void handle(Event event) {
                      System.out.println("Changed");
                  }
              });

              root.getChildren().addAll(tabPane);


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

            kwwong Kinsley Wong (Inactive)
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: