Text Editor


How to restrict the text editor such that its doesn’t take character as input . only takes digits .




Thank you . Initially I was using label now I have changed it to TextEditor . my requirement is On Text Change I have validate the text and take action accordingly . But I have a problem with Text Editor as the text change event occur even on single character enter in the text Editor . That means I will not get complete text . I cant use focus lost event due to my UI design . Can you please suggest me the way out


The Label itself uses a TextEditor, and the callback you were using happens in response to the TextEditor::Listener::textEditorReturnKeyPressed() callback. You should get the same sort of behaviour by responding to that callback yourself.


But the problem is I am not getting the event textEditorReturnKeyPressed() . I am receiving focus lost , text changed , escape key pressed event but not retrun key pressed .When is the return key pressed event raised


have a guess


I know it should be on Enter key press :smiley: but problem is I am not receiving the event


[code] /** Changes the behaviour of the return key.

    If set to true, the return key will insert a new-line into the text; if false
    it will trigger a call to the TextEditor::Listener::textEditorReturnKeyPressed()
    method. By default this is set to false, and when true it will only insert
    new-lines when in multi-line mode (see setMultiLine()).
void setReturnKeyStartsNewLine (bool shouldStartNewLine);[/code]



I have set it to false . may be my work will be done with focus lost but problem is … I have multiple components in my UI . The problem is when a click on TextEditor focus is in text Editor but when i click on some other components in my UI , for some componenets i do get TextEditor focus lost event but for few I dont receive it … I am missing something .


I’ve no idea, it’s hard to guess what you might be doing. If I were you, I’d get in there with the debugger and trace what happens when this method should be called.


Thank you for the response . I have a question : Suppose I have multiple components in my UI . Suppose i have a text editor in one of the component . Suppose the focus is in Text Editor . When I do mouse click on any other the components or the same component , does that component acquire focus and Text Editor loss the focus . How to make the component acquire the focus on mouse click


Open the Component class documentation.

Search for words like “focus”, “keyboard”, “click”, etc

You’ll find methods with helpful names like “setMouseClickGrabsKeyboardFocus”, “wantsKeyboardFocus”, and others. They have explanations. Read the explanations.

If any of the explanations aren’t clear enough, please let me know which ones, and I’ll improve them.

You may also find this helpful:


I updated to head last week after being 3-4 months behind, and suddenly, some TextEditors that were responding to return key presses to launch actions aren’t do so anymore. The TextEditor::Listener class’s textEditorReturnKeyPressed() method isn’t being called, and if you subclass TextEditor and override returnPressed(), that’s not being called either. I tried to look through the file history of the juce TextEditor class to see what might have changed, but my git client had problems “walking the tree” (!?), and I didn’t get too far that way. I’m working on iOS, and it may well be an iOS specific issue… I’m going to dig around in the native code to see if I can’t find any problems there…