Tabbedcomponent wont work as expected when i make it parent class

so here is my TabComponent which inherits TabbedComponent

class TabComponent : public TabbedComponent
    TabComponent(TabbedButtonBar::Orientation orientation) : TabbedComponent(orientation) {}
     // paint & resized method here

and this is how i set up a tabbed component

class EditorArea : public Component
    /// paint & resized method here
	TabComponent tabComponent;
	Viewport viewport;

EditorArea::EditorArea() : tabComponent(TabbedButtonBar::Orientation::TabsAtTop), viewport("Test1")
	tabComponent->addTab("test", Colour(123, 123, 123), &viewport, true, 0);

void EditorArea::resized()

but it doesnt work. it should display the tabComponent with 1 tab.
As you can see tabComponent is of type TabComponent (my class that inherits TabbedComponent) but when i change it to TabbedComponent it works. is there anything i should do if i want to inherit from TabbedComponent?

The documentation how this class is used is indeed not very verbose. You need to look either at the JuceDemo or at the sources.
You are overriding resized and paint, but there is indeed a lot happening:

The TabbedComponent is the container for other components to show up. You add any arbitrary Component using TabbedComponent::addTab()

See the Juce Demo here:

The resized() and paint() methods are kept, only the constructor is changed, which you don’t need to do, because all methods called here are public, so you can call them on an instance as well.

Do you need to create a subclass?


it works. you are right i never really thought to look at the source file. thanks for that !

Do you need to create a subclass?

yes because ill have vector of viewports and i dont want to handle it separately from the tabbedcomponent. would you verify if that reason is alright? thanks.

Glad it works.

That’s really up to you. I think it makes sense just have the vector alongside the tabbed component.
I would only put that into a subclass, if I also want to change the behaviour of the tabbed component, e.g. if I want my custom drawing etc.

EDIT: I think you can even do without the vector, because the tabbedComponent stores them anyway. Only drawback is, that then they are Components that you have to dynamically cast to Viewport, if you want to call viewport specific methods. But the bonus is, you don’t have to worry about ownership, lifetimes etc.