Daniel Tsai
Daniel Tsai

Reputation: 959

Can I prevent a tabs from switching tab?

I have a tabs for a wizard process.

Is it possible to achieve that if certain conditions are not met, avoid proceeding to the next step (avoid switching to the next tab)?

Could I achieve my requirement in the SelectionListener?

Upvotes: 1

Views: 36

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

SelectionListener is problematic as it's a little too late and doesn't provide us with an object we can use.

First disable the swipe action by using setSwipeActivated(false);. Swiping is a bit problematic to block as it provides a preview of the next tab.

You can override setSelectedIndex(int, boolean) to return in such a case. Alternatively you can do something like this:

private void enableTabs(Tabs t, boolean enable) {
     for(Component c : t.getTabsContainer()) {
         c.setEnabled(enable);
     }
}

Then use enableTabs(t, false) to disable all the tabs and use true later to re-enable them.

Upvotes: 0

Related Questions