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

Tab.setOnSelectionChanged fires twice even if nothing has changed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Labels:

      Description

      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();
          }
      }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: