How the Toolbar handle ToolbarButton click event?


#1

Hi,
I’m a new guy using JUCE which is great c++ library.
I’ve written a simple program using toolbar,I want the program call buttonClicked(Button * button) when some ToolbarButton be clicked on my toolbar, unfortunately the method buttonClicked never be executed.
My code is here:

class MyToolBar : public Toolbar,
		          public ButtonListener
{
public:
	MyToolBar()
	{
		this->addDefaultItems(m_factory);
		this->getItemComponent(MyToolbarItemFactory ::tb_setting)->addListener(this);
	}

	~MyToolBar()
	{
	
	}

	void buttonClicked(Button * button)
	{
            // do something
	}


private:
	MyToolbarItemFactory m_factory;
};

Can somebody tell me why,thanks.


Listening to toolbar buttons click events
#2

You need to add a listener to the button on the toolbar, you need to sublcass the ToolbarItemFactory and add listeners to the created items, the Toolbar class does not react to the components on it


#3

hi,
Yes, you’re right, the listener should be added when create ToolbarButton in ToolbarItemFactory .
Thanks.