I don't konw this question


in my code :
addAndMakeVisible (tb = new TextButton (String::empty));
tb->setButtonText (T(“Over me”));
tb->addButtonListener (this);

void MainComponent::mouseDown (const MouseEvent& e)
if((e.x>=52&e.x<=172)&e.y>=240)//Show the following areas of the TextButton ,contain TextButton areas.
//tb->setBounds (52, 240, 120, 32);
tb->setButtonText (T(“love me”));
lb->setText (T(“Down me”),true);
on Button ,mouseDown() don’t work,BUT,other positions are very well.why?


It’s hard to tell what you’re trying to do here, but a few things that might help.

  1. If you want to handle a button being clicked then make your component inherit from Button::Listener and implement void buttonClicked(Button *b) (and/or buttonStateChanged(Button *b))

  2. Your if statement has single & instead of double &&

  3. And also the T’s aren’t recommended anymore I think.



You should also know:

  • for better reading ,when you paste some code snippets, use the ‘Code’ button and surround your code with it (use the ‘Preview’ button to see how it looks).
  • For the ButtonClicked() callback mentioned by Graeme to actually work, you need to register the class (Buttton::Listener) using
  • Check the example projects, there’s plenty of useful stuff there…


I think ,maybe I didn’t describe clearly.I know when mouse put on button, It’s nothing.But on other position,
eg. at Point (180,280), Display text.WHY?
BTW, window’s size as follows setSize (600, 300);


Ok, now I got you…

Cause the button is a different component, lying on top of your component, and has it’s own MouseDown() function which is the one called when you click on it.


Thank you.


Wow. Interesting use of the & operator there. You might want to learn about the difference between && and &.

Wow. Interesting use of the & operator there. You might want to learn about the difference between && and &.


Also, you’ll find a large button at the bottom of the keyboard. It makes a ‘space’. It’s traditional to use it between words, to make written language easier to read. I find that, since you can put any whitespace you want in C style code, it also makes code easier to read, and makes your intent clearer.


Is this what you mean: