How to recognize which button was clicked in Property Pane of JuceDemo example?

In this example when i clicked button, it only show one alertwindow.So i want When i click button 2,I want to show a button 2 and i will be show alertWindow ("This is button 2 ")?
Can anyone help me,please?
Thanks all.

Pass the components propertyName into the message:

AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon, “Action Button Pressed”, “Pressing this type of property component can trigger an action such as showing an alert window!”);

Something like:
AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon, “Action Button Pressed”, "This is " + propertyName);

Thank you but it does not work.

Create a new GUI Project, and copy / paste these two.



#include "../JuceLibraryCode/JuceHeader.h"

class MainContentComponent   : public Component, public ButtonListener // Note the ButtonListener

    void paint (Graphics&);
    void resized();

    /* We need this so we can know the button was clicked. Note also that we have 'public ButtonListener' above as well. **/
    void buttonClicked (Button* buttonThatWasClicked) override;

    /* This sets up a couple of TextButtons **/
    ScopedPointer<TextButton> button1, button2;



#include "MainComponent.h"

        setSize (600, 400);

        button1 = new TextButton("button1"); // Set the name of the button
    addAndMakeVisible(button1); // add the button
    button1->setComponentID("button1"); // set Component ID
    button1->setButtonText("Button #1"); // Set the buttons text
    button1->setBounds(20, 20, 100, 20); // Set the location of the button
    button1->addListener(this); // So we know when it is pressed.
    // Rinse, repeat
    button2 = new TextButton("button2");
    button2->setButtonText("Button #2");
    button2->setBounds(20, 50, 100, 20);


void MainContentComponent::paint (Graphics& g)
    g.fillAll (Colour (0xff001F36));

void MainContentComponent::resized()

/* This occurs when the button is clicked. Because we added button1->addListener(this) and button2->addListener(this) in the constructor.**/
void MainContentComponent::buttonClicked (Button* buttonThatWasClicked)
    if (buttonThatWasClicked == button1 || buttonThatWasClicked == button2)
        AlertWindow::showMessageBox(AlertWindow::InfoIcon, "Button Clicked", "You clicked: " + buttonThatWasClicked->getComponentID() + " Which has text of: " + buttonThatWasClicked->getButtonText(), "OK");   

I knew it and i am creating example like Property Demo which use propertyPanel.addSection (“Buttons & Toggles”, createButtons (3)) or something same like that.My problem is that not recognize exactly which array of button in function creatButtons().
Btw,thank you for your enthusiasm and helping me.

This should create the buttons, no?

static Array<PropertyComponent*> createButtons (int howMany)
    Array<PropertyComponent*> comps;

    for (int i = 0; i < howMany; ++i)
        comps.add (new DemoButtonPropertyComponent ("Button " + String (i + 1)));

    for (int i = 0; i < howMany; ++i)
        comps.add (new BooleanPropertyComponent (Value (Random::getSystemRandom().nextBool()), "Toggle " + String (i + 1), "Description of toggleable thing"));

    return comps;

And this should occur when you click the button:

void buttonClicked() override
    AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon, "Action Button Pressed",
                                      "Pressing this type of property component can trigger an action such as showing an alert window!");

Or have I misunderstood completely?

Sorry,i am not good at english.
Simple, i click button 1,it will show “this is button 1 and it will do function 1” or i click button 2,it will show “this is button 2” and it will do function 2.It is my purpose.

You could do the above for message.

And do a if or switch on the componentID for laughing different functions?