B4J Question "SelectedText" Property for Text Controls?

dilettante

Active Member
Licensed User
Longtime User
Often one needs to do things like replace part of the text of a "Text" control, and in particular with a TextArea one needs to append a new line to "log" additional information.

The "slow boat" in VB6 and earlier was to retrieve the entire Text property's value, concatenate, and then store the new bigger string back into the control by writing to the Text property. This can be improved on by moving the caret (insertion point) to the end of the text by using the maximum possible length value and then setting the SelText property.

Even though the JavaFX TextArea does have a method named "replaceSelection" this does not appear to be exposed in B4J.

B4X:
Sub LogIt(Text As String)
  'Does not work:
  'TextLog.SetSelection(0x7ffffff, 0x7fffffff)
  'TextLog.SelectedText = Text & CRLF <-- No such property exposed.
 
  'Must use:
  TextLog.Text = TextLog.Text & Text & CRLF
End Sub

Is this an omission or am I missing some other syntax or workaround? Since we do have SetSelection as well as SelectAll and other members exposed to us it seems logical we'd have a way to read and write the selection.
 

Gaver Powers

Member
Licensed User
Longtime User
Is there a simple method for clearing the content of a text or text area control.
I looked at the docs referenced above and could not find a clear method or property that I could use to accomplish this.

Or is the only solution to use the JavaObject method in #2 above?
 
Upvote 0
Top