(multiple) TextEditor selection behaviour not as desired



First and foremost, my hat off to Jules for the magnificent JUCE - maybe now I can finally lose the Borland VCL and that makes me a happy guy :slight_smile: [fwiw, I am not using Borland with Juce, I use Code::Blocks and GCC. Not sure of Juce version - is at least 1.45… as a side-issue, should I be aiming to use the SVN version?]

I have a component with several TextEditor components embedded - when the contents of one editor is selected and highlighted, and focus is changed to another editor, the selection range remains highlighted in the original editor. Is this intended behaviour, am I missing a trick here to change the behaviour, or worst-case is there an easy way I can change this?

Please be gentle - I’m a Juce noob (and a “true” C++ noob too I suppose).



Yes, that’s the correct behaviour - all text editors do it that way by default. Maybe you need to use setSelectAllWhenFocused()?


OK, thanks for the answer; certainly setSelectAllWhenFocused() is something I would be wanting, so thanks for the heads up on that one. Currently the selection range remains once the text box loses focus, but re-focussing the same text box loses the selection anyway (which of course that method you prompted should “correct” as I would prefer it to auto-select the entire contents on focus).

I must confess I’ve never seen a text edit box retain its selection once it loses focus, but I’m guessing I could amend that by adding listeners to them and manually call setHighlightedRegion() when they lose focus? It’s effectively a “cosmetic” issue tbh, but sure looks weird hehe.

I neglected to mention that this component doesn’t presently “exist” in my app, it’s only in the Jucer right now so I am seeing this behaviour when testing the component - presumably the behaviour ought to be reasonably identical when linked into my app?



Single-line textboxes probably tend to clear the selection when you re-focus, but I think most multi-line ones will keep it. I just tried it in firefox now and it does just that. That’s why I added the option flag so you can change this.


Good point! These are indeed single-line beasts. Anyway, I’ll press on trying to integrate the component into the app and take it from there!

Thanks again for the replies


So I noticed when using setSelectAllWhenFocused (true) and a tab out of the TextEditor the selection is still shown in a single line Edit Control… I compared the behavior to other apps to verify I wasn’t losing my mind… Xcode is a good example… when you select all in an edit control then tab out there is no selection shown.

Is this something I should fix myself using…

or something that should be ‘fixed’ in JUCE?