Button Logic Help


I have an app that has a reset button that resets some parameters internally, but I dont want it easily clicked. The implementation I would love to have consists of the reset button being disabled by the GUI constructor, then, an additional button called “Unlock” that when held down, causes the reset button to be available, but when the unlock button is released, the reset button is disabled again. I think this code would work,


But I dont know where to place it. It doesn’t work inside the unlock button code, would I have to place it in an event loop area? because the state of the button needs to be read at every instant. I’m still a beginner, my apologies if this is something really simple.


You want to listen to the button, so that you’re being told every time its state changes.
You can probably find some code examples in the Juce Demo. In short : inherits Button::Listener, and implement buttonClicked() and buttonStateChanged() :

void buttonStateChange (Button* b) override
     if (b == lockButton && lockButton->isDown())

and don’t forget to register/unregister as a listener to the button in your constructor/destructor
lockButton->addListener (this)
lockButton->removeListener (this)


My knowledge of this is pretty limited, I just started to learn how to develop GUI apps back in December and JUCE was my first framework. I usually have issues using the JUCE demo app because its so massive its hard to find examples of things, but I’ll give it another look. I’ll look into this and see if I can find out where to put the code you suggested. I understand everything you wrote, just need to understand where to place it. Thank you very much. Much appreciated.


Hope this helps a little.

class YourEditor : public Button:Listener
void buttonStateChange (Button* b) override;


// Your button

void YourEditor::buttonStateChange (Button* b) override
if (b == lockButton && lockButton->isDown())

void YourEditor::buttonClicked(Button* b)



WOW! Thanks a ton cocell! I’m a third year student in programming and haven’t taken and GUI classes yet, so this, being my first forray into GUI programming, has proven to be a challenge, since I’m attacking it outside of school. The issue I was having was trying to figure out how to override a method, since I have never overridden one (lots overloading, but not overriding). Thank you very much. I’ll whip these files up and give it a shot.