Uploaded image for project: 'Pivot'
  1. Pivot
  2. PIVOT-751

TabPaneSelectionListener#selectedIndexChanged called twice when first tab is inserted

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.0, 2.0.1
    • 2.0.2
    • wtk
    • None

    Description

      If you add a tab to an empty tabpane, two selectedIndexChanged events are called. I.e, when you add a TabPaneSelectionListener to a tabpane and call:

      tabpane.getTabs().add(component);

      .. the listener fires twice, with previousSelectedIndex set to -1 and then 0.

      The two events are fired by line 68 and 72 in TabPane.java:

      68 tabPaneListeners.tabInserted(TabPane.this, index);
      69
      70 // Fire selection change event, if necessary
      71 if (selectedIndex != previousSelectedIndex)

      { 72 tabPaneSelectionListeners.selectedIndexChanged(TabPane.this, selectedIndex); 73 }

      This could be fixed by taking into account that previousSelectedIndex might have been -1 when invoked, like this:

      if (selectedIndex != previousSelectedIndex && previousSelectedIndex > -1) {

      See this thread for more info: http://apache-pivot-users.399431.n3.nabble.com/TabPaneSelectionListener-selectedIndexChanged-called-twice-when-first-tab-is-inserted-td3022515.html

      PS: According to Chris, CardPane and Accordion behave in the same way, so any changes to TabPane should also be made to these for consistency.

      Attachments

        1. PIVOT751.java
          2 kB
          Christopher James Bartlett
        2. PIVOT751.txt
          1 kB
          Christopher James Bartlett

        Activity

          People

            smartini Sandro Martini
            edvin Edvin Syse
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: