D dilettante Active Member Licensed User Longtime User Dec 9, 2013 #1 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. Code: Copy 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.
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. Code: Copy 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.
Erel B4X founder Staff member Licensed User Longtime User Dec 10, 2013 #2 You can use JavaObject to call replaceSelection: Code: Copy Dim jo As JavaObject = TextArea1 jo.RunMethod("replaceSelection", Array As Object("New Text")) Upvote 0
You can use JavaObject to call replaceSelection: Code: Copy Dim jo As JavaObject = TextArea1 jo.RunMethod("replaceSelection", Array As Object("New Text"))
D dilettante Active Member Licensed User Longtime User Dec 10, 2013 #3 Thanks. That looks like a viable workaround. Upvote 0
Gaver Powers Member Licensed User Longtime User Jan 29, 2014 #4 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
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?
Erel B4X founder Staff member Licensed User Longtime User Jan 29, 2014 #5 Code: Copy TextField1.Text = "" Upvote 0