Getting int of selected tab

Hi all,

TabSheet has a setSelectedTab(int) method, but no matching getSelectedTab that returns an int. I need this for some code that needs to replace a tab sheet but select the same tab (by position) that was selected before. I’ve implemented it as below in a class that contains the tab sheet being used – is there a better way I’m not seeing?

I understand the reasoning for how tab sheet currently works, but it confuses me that getSelectedTab really returns the component of the selected tab whereas getTab returns an actual tab.

    public int getCurrentTab() {
        final TabSheet.Tab selected = tabsheet.getTab(tabsheet.getSelectedTab());
        for (int i = 0; i < tabsheet.getComponentCount(); i++) {
            if (selected.equals(tabsheet.getTab(i))) {
                return i;
        return 0;


Hi Bobby,

There is a method called getTabPosition(Tab) that returns the index of the Tab. Basically you can get it with:



That’s great – thanks!

Since there’s a setSelectedTab(int), doesn’t it make sense to provide a getTabIndex()? The proposed solution is terribly verbose and obsure.

This is a bit old, but just found myself wondering the same and decided to create the following enhancement issue for framework