Difficulty implementing currentTabChanged call back

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.


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


    GuiWorkAudioProcessorEditor (GuiWorkAudioProcessor&);

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


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…

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 ?

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

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?

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…

1 Like

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

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); };

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