TextEditor update


I am having some trouble understanding how TextEditor works. I have a plugin in which I want to be able change some text assigned to a TextEditor and use it.

In the PluginEditor.cpp file, I created a TextEditor variable for an url. I predefined it with a link and then I am passing it to a function, but I want to be able to change the url from the interface and I am a bit confused how to properly do it. How can I change it in real time?

In my editor file I have:

urlBox.setText ("https://www.google.com");
addAndMakeVisible (urlBox);

URL url (urlBox.getText());
x = myFunction(url);

Thanks! :slight_smile:

Which step is not working for you? Is the TextEditor not displaying in your UI? Or the user can’t type into it? Or you can’t retrieve it’s value using getText()?

I can’t retrieve the new value

You may want to attach a callback to the TextEditor, triggered either when the user types inside the box (onTextChange) or presses the return key (onReturnKey). Something like this:

addAndMakeVisible (urlBox);
urlBox.onTextChange = [this] { myFunction(urlBox.getText()); };

Or have a Button component that the user can click to submit their url when they’ve finished typing, and call myFunction in that button’s callback.

1 Like