When swiping to the previous tab, I add a new tab with 'insertTab' with index 0. Then I change the current tab with 'setSelectedIndex' (because current index is now 1). This is going ok when doing this for the first time (so when first showing the Tabs, I show the current one with current date, make a new one on index 0, change the index to 1 and I can swipe 'back' to the newly added tab with index 0).
I'm trying to add new tabs in the SelectionListener: when I'm on tab with index 0, I add a new one on index 0. The problem is: setSelectedIndex is not going well here. I'm always staying on the newly added tab at index 0, but I want to go to the 'current' tab, with new index 1. I hope you understand what I mean.
Here is my code:
public class SelectTabListener implements SelectionListener
{
public void selectionChanged(int oldSelected, int newSelected)
{
DateContainer dc = (DateContainer)swipeContainer.getTabComponentAt(newSelected);
Date currentDate = dc.getDate();
dateLabel.setText(dateFunctions.getDateString(currentDate));
if (newSelected == 0)
{
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
c.add(Calendar.DAY_OF_MONTH, -1);
Date newDate = c.getTime();
DateContainer newContainer = getDayListContainer(newDate);
swipeContainer.insertTab("", null, newContainer, 0);
swipeContainer.removeSelectionListener(selectTabListener);
swipeContainer.setSelectedIndex(newSelected + 1);
mainContainer.revalidate();
swipeContainer.revalidate();
swipeContainer.addSelectionListener(selectTabListener);
}
}
}