TabSheet bug

I try to use

replaceComponent

method of
TabSheet
component and it doesn’t work properly.
Components is replaced, but tab captions does not.
When both components is exist last lines of code does not needed. There is was only rearrange of components.


    public void replaceComponent(Component oldComponent, Component newComponent) {
...
                components.remove(oldComponent);
                components.add(newLocation, oldComponent);
                components.remove(newComponent);
                components.add(oldLocation, newComponent);
...
            if (newTab != null) {
                // This should always be true
                newTab.setCaption(oldCaption);
                newTab.setIcon(oldIcon);
            }
            if (oldTab != null) {
                // This should always be true
                oldTab.setCaption(newCaption);
                oldTab.setIcon(newIcon);
            }

Maybe I’m wrong in understanding the purpose of this function?

Thank You for Your attention.

I guess the problem is that a TabSheet doesn’t contain Components directly - it holds Tabs. Tabs contain the component, caption and other stuff (icon?). If I recall correctly, when you say tabsheet.addComponent(component) it actually creates the Tab object and puts the component in it and adds the components caption to the tabs caption manually.

It seems that when you do replaceComponent it just changes the component inside the Tab instance, thus leaving the other info intact, like the caption. I guess it works as planned, but if it is a good or bad decision is another topic. I see no reason why everything should not be updated at the same when you do a replaceComponent.