How do I add a mouseDown MouseListener to a TextEditor?

How do I add a mouseDown MouseListener to a TextEditor and where do I define it?

class ExampleAudioProcessorEditor  : public AudioProcessorEditor // ?
{
    private:

    TextEditor aTextEditor;

    // ?
};

 ExampleAudioProcessorEditor::ExampleAudioProcessorEditor (ExampleAudioProcessor& p)
: AudioProcessorEditor (&p), processor (p)
{
    // ?
    addAndMakeVisible(aTextEditor);
}

// ?

Can you elaborate, what exactly you want to achieve?
Please bear in mind, that every Component is already a MouseListener…

Add to your ExampleAudioProcessorEditor example:

aTextEditor.addMouseListener (this, true);

This will make the TextEditor forward all mouse events to your ExampleAudioProcessor instance’s void mouse* (MouseEvent&) callbacks. You can then use the MouseEvent's originComponent and eventComponent properties to filter and process the events to trigger whatever you want.

My plug-in requires the user to login with an email address and password. When the plug-in’s GUI is active, the text editor has keyboard focus, so therefore none of the host application’s key commands work. So then I set aTextEditor.setWantsKeyboardFocus() == false to allow the host application’s key commands to work as normal. So now I need to set aTextEditor.setWantsKeyboardFocus() == true when the user clicks on the text, otherwise the TextEditor text cannot be edited.

Ok thanks, I’ll try and figure this out.

That’s the kind of thing a Label is designed for - it’s just displays the text until you click it, and only then does it create a TextEditor and grab focus.

1 Like

Sounds good, thanks for the help.