Getting TextWidth from a TextEditor after a word wrap


I’m trying to create a textEditor that has a button right after the text, in order to do that I need the text width, I am using this function to get the width
textEditor.getFont().getStringWidth(textbox.getText()) ;

This works well when the text is only one line, however, when the text is multiline, and WordWrap is enabled I can’t get the accurate text width, is there some way to do this other than creating your own word wrapper?

you can loop over the string and get a new textwidth for the substrings of one line, so everything that is seperated with ‘/n’ + the one after the last seperator

then the maximum textwidth of those is the actual textwidth of the whole

1 Like