How can I sort tabs and get tabs by name in tabbedcompont?


#1

Stupid question for sure :slight_smile: There are many workarounds. But what I want to know is if the Tabbedcomponent itself should have a member function like ‘getTabbyName’ or ‘sortTabsByName’? When I have many tabs and need to delete or add tabs frequently, to maintain the tab index is boring. And also if I want to keep the original tab order(by names), I don’t know how I could do it without rebuild the tab list.


#2

Should return a StringArray. 

Then you can look for your tabName and or get the index assuming this StringArray is storing the tabs in the same order as they come in and get created. I bet they are... 

After you have an index you can use: 

[code]removeTab(yourFoundindex)[/code]

to remove your found tab. 

As far as reordering or sorting tabs by name I would just rebuild the tabs. Maybe you can get the tab content components out of the tab bar then rebuild the tab bar and stick your content back into each tab. That's if you don't want to rebuild the tab content every time. 

Just some thoughts.

Should return a StringArray.

Then you can look for your tabName and or get the index assuming this StringArray is storing the tabs in the same order as they come in and get created. I bet they are…

After you have an index you can use:

to remove your found tab.

As far as reordering or sorting tabs by name I would just rebuild the tabs. Maybe you can get the tab content components out of the tab bar then rebuild the tab bar and stick your content back into each tab. That’s if you don’t want to rebuild the tab content every time.

Just some thoughts.


#3

Thanks alot, aiit!

I think you are right. To rebuild the whole component seems the only solution. If so, I expect this should be done by the library component itself. They are generic methods IMO. Could Jules please make some improvement?


#4

It’s got a moveTab method - you could use that to do a sort quite easily, without needing to add or remove any tabs - it’s surely just a few lines of code…


#5

Thank you! Jules. I found that function in the TabbedButtonBar class. That should work.