# Tabbedcomponent wont work as expected when i make it parent class

**URL:** <https://forum.juce.com/t/tabbedcomponent-wont-work-as-expected-when-i-make-it-parent-class/22197>\
**Category:** General JUCE discussion\
**Created:** [May 2, 2017, 2:25pm UTC](https://forum.juce.com/t/tabbedcomponent-wont-work-as-expected-when-i-make-it-parent-class/22197 "2017-05-02T14:25:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xenovia12](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenovia12/32/2193_2.png) [@xenovia12](https://forum.juce.com/u/xenovia12)\
**Post date:** [May 2, 2017, 2:25pm UTC](https://forum.juce.com/t/tabbedcomponent-wont-work-as-expected-when-i-make-it-parent-class/22197/1 "2017-05-02T14:25:03Z")

</div>

so here is my TabComponent which inherits TabbedComponent

```
class TabComponent : public TabbedComponent
{
public:
    TabComponent(TabbedButtonBar::Orientation orientation) : TabbedComponent(orientation) {}
   ~TabComponent();
     // paint & resized method here
private:
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabComponent)
};

```

and this is how i set up a tabbed component

```
class EditorArea : public Component
{
public:
    EditorArea();
    ~EditorArea();
    /// paint & resized method here
private:
	TabComponent tabComponent;
	Viewport viewport;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EditorArea)
};

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

void EditorArea::resized()
{
       tabComponent.setBounds(getBounds());
}

```

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`?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 2, 2017, 3:13pm UTC](https://forum.juce.com/t/tabbedcomponent-wont-work-as-expected-when-i-make-it-parent-class/22197/2 "2017-05-02T15:13:59Z")

</div>

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:

> <https://github.com/WeAreROLI/JUCE/blob/master/modules/juce_gui_basics/layout/juce_TabbedComponent.cpp#L252>

The TabbedComponent is the container for other components to show up. You add any arbitrary Component using [TabbedComponent::addTab()](https://www.juce.com/doc/classTabbedComponent#a0d7761f1c372260ca4a2acb36a320e10)

See the Juce Demo here:

> <https://github.com/WeAreROLI/JUCE/blob/master/examples/Demo/Source/Demos/WidgetsDemo.cpp#L1510>

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?

HTH

---

<div class="post-metadata">

**Author:** ![xenovia12](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenovia12/32/2193_2.png) [@xenovia12](https://forum.juce.com/u/xenovia12)\
**Post date:** [May 2, 2017, 3:33pm UTC](https://forum.juce.com/t/tabbedcomponent-wont-work-as-expected-when-i-make-it-parent-class/22197/3 "2017-05-02T15:33:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 2, 2017, 3:39pm UTC](https://forum.juce.com/t/tabbedcomponent-wont-work-as-expected-when-i-make-it-parent-class/22197/4 "2017-05-02T15:39:49Z")

</div>

Glad it works.

> [@xenovia12](#):
>
> yes because ill have vector of viewports and i dont want to handle it separately from the tabbedcomponent

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.
