If I set the selectedTab of a Tab Strip, but that tab is not currently on the screen because I have too many tabs to show on one screen, is there a way to set focus to that tab so that the user can see it is selected.
Currently it remains off screen so very confusing to user.
I was looking for a solution to this recently and ended up writing a small script to achieve it.
I don’t know if it’s the best solution but it works for me. Call the below script in the PropertyChange event (filtered for selectedTab property) for the Tab Strip component.
# Shift the tab strip so the selected tab appears in view (when there are too many tabs to show at once).
# The Tab Strip component should be passed in to the 'tabs' parameter.
def showSelectedTab(tabs):
cmpnts = tabs.getComponents()
offset = cmpnts[0]
pnl = cmpnts[1]
x = 0
w = 0
for c in pnl.getComponents():
if c.isSelected():
x = c.getX()
w = c.getWidth()
break
tabsW = (tabs.width - offset.width)
os = offset.getCurrentOffset()
maxos = pnl.width - tabsW
if maxos < 0:
maxos = 0
if x < os:
os = x
offset.setCurrentOffset(os)
tabs.revalidate()
elif x + w > os + tabsW:
os = x - (tabsW - w)
if os > maxos:
os = maxos
offset.setCurrentOffset(os)
tabs.revalidate()