TabSheet & focus

I have 2 tabs.
Sometime, by code, I need to set the focus on a given field, however if the field receiving focus is not in the visible tab I don’t see any effect.
I expected the tab containing the focus is allways the visible one.
How can I solve ?
Tks
Tullio

You can always use TabSheet.setSelectedTab() before you focus a component inside the tab.

Quite easy if I create a simple, single UI and I know in wich tab is a given field, more difficult if I need to create some infrastructure which don’t know in where the field is included.
Any suggesion ?
Tks

You can loop through the parents of the field, and when you encounter a TabSheet, use getTab(Component) method to the tab for the previous parent you looped through.

Something along these lines (not tested):

[code]
Component currentParent = field.getParent();
Component previousParent;

do {
if(currentParent.getParent() == null)
break;
previousParent = currentParent;
currentParent = currentParent.getParent();
} while( !(currentParent instanceof TabSheet) );

if(currentParent instanceof TabSheet) {
Tab tab = ((TabSheet) currentParent).getTab(previousParent);
}
[/code]Hope this helps!