# Difficulty implementing currentTabChanged call back

**URL:** <https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977>\
**Category:** Audio Plugins\
**Created:** [March 26, 2018, 11:51pm UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977 "2018-03-26T23:51:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CGill](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@CGill](https://forum.juce.com/u/CGill)\
**Post date:** [March 26, 2018, 11:51pm UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977/1 "2018-03-26T23:51:26Z")

</div>

Hi all,

I’m trying to make a GUI that updates variables when a new tab is selected.  
I think i should be using the ‘currentTabChanged’ call back method from Tabbed Component Class although i’m having problems implementing this.

**Header:**

```
class GuiWorkAudioProcessorEditor : public AudioProcessorEditor,
								private Slider::Listener,
								private TabbedComponent

{

public:
    GuiWorkAudioProcessorEditor (GuiWorkAudioProcessor&);
    ~GuiWorkAudioProcessorEditor();

//==============================================================================
void paint (Graphics&) override;
void resized() override;
static const char* gidiBg_png;
static const int gidiBg_pngSize;

private:

void sliderValueChanged(Slider * slider) override;
void currentTabChanged(int newCurrentTabIndex, const String& newCurrentTabName) override;

// This reference is provided as a quick way for your editor to
// access the processor object that created it.
GuiWorkAudioProcessor& processor;
TabbedComponent tab;
Slider midiVolume,altSlider;
Image cachedImage_gidiBg_png_1;
Font font;

```

So by inheriting the TabbedComponent class i can then override the callback method … but this leads to error in my .cpp file…

 ![error](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/3/3ddbd8c8c67fda8e3a86d8ea61f22d2c292393db.PNG)

The error if i hover over opening brace reads “no default constructor exist for class Juce::TabbedComponent” … These only occur when inheriting the Tabbed Component Class.

Anyone have any ideas of whats happening here ?

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [March 27, 2018, 1:36am UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977/2 "2018-03-27T01:36:35Z")

</div>

> [@CGill](#):
>
> TabbedComponent tab;

Not sure why the errors are showing where they are, but the member variable **tab** is the cause of the **no default constructor** error.

---

<div class="post-metadata">

**Author:** ![CGill](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@CGill](https://forum.juce.com/u/CGill)\
**Post date:** [March 27, 2018, 12:59pm UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977/3 "2018-03-27T12:59:18Z")

</div>

The errors only show when i inherit TabbedComponent… I reckon that’s the cause but unsure of how to fix it. The constructor for **tab** is taken care of with:

```
GuiWorkAudioProcessorEditor::GuiWorkAudioProcessorEditor (GuiWorkAudioProcessor& p )
: AudioProcessorEditor (&p), processor (p) , tab(TabbedButtonBar::Orientation::TabsAtTop)  

```

or am i wrong?

Literally cannot figure out how this to remedy this… what is the most appropriate way to implement the Callback for a changed tab?

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [March 27, 2018, 1:06pm UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977/4 "2018-03-27T13:06:15Z")

</div>

You need to make a new component class that inherits TabbedComponent, your AudioProcessorEditor should not inherit from TabbedComponent. Your AudioProcessorEditor class should then hold an instance of that customized TabbedComponent.

This is admittedly rather annoying, I don’t know why the JUCE developers have not added a TabbedComponent::Listener class or something to get notifications about the tab page changing…

---

<div class="post-metadata">

**Author:** ![CGill](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@CGill](https://forum.juce.com/u/CGill)\
**Post date:** [March 27, 2018, 1:15pm UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977/5 "2018-03-27T13:15:23Z")

</div>

ah i see , yes a listener class would have saved me a lot of hassle!  
Thanks for info,i will try this method

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [March 27, 2018, 1:18pm UTC](https://forum.juce.com/t/difficulty-implementing-currenttabchanged-call-back/26977/6 "2018-03-27T13:18:57Z")

</div>

Here’s my implementation that uses std::function so you can be saved from the hassle of passing additional pointers/references into the custom TabbedComponent. You would replace the TabChangedFunc with a lambda in your AudioProcessorEditor class code to do what you need to be done when the tab changes, for example : mytabs.TabChangedFunc = [this](int index){ tabchanged(index); };

```auto
class MyTabComponent : public TabbedComponent
{
public:
	MyTabComponent() : TabbedComponent(TabbedButtonBar::TabsAtTop)
	{
		TabChangedFunc = [](int) {};
	}
	void currentTabChanged(int index, const String&) override
	{
		TabChangedFunc(index);
	}
	std::function<void(int)> TabChangedFunc;
};

```
