Multiline Text Area

Hello there !

Using Xojo under Kubuntu 22.04 I have the following question…

I use a text area for display various messages from the app to the user. Its handy because old messages are always here.
The new messages are appended to the existing text area text with a new line (chr(10)).
The text area is multiline and has a vertical scrollbar.

My problem is that each time I add a message the text area come back and display the first lines of the text… The new messages are at the bottom and I should use the scrollbar to see them.
I try to put a ‘Zon_dial.ScrollPosition = 100000’ into TextChange but without success.

So what can I do to have always the last lines of the text displayed ?

Thanks and regards.
Philippe

You talk about “VerticalScrollPosition” correct?

No. “TextArea.ScrollPosition” as I write.
I will give a try to TextArea.VerticalScrollPosition" instead.

This is an undocumented feature. I’d be not surprised if it does not work. :wink:

Are you using AddText to append the new message? Using the “+” operator resets the entire control.

Yes I use the “+” operator. I can change for AddText but there is a lot here and there in the code…

Using VerticalScrollPosition change the behavior of the text area.
Now the scrollbar is set to the middle after a text change.

Setting it to the last line or beyond the last line will move the vertical scrollbar’s thumb to the bottom, not necessarily displaying the last line at the top of the control.

Again, taken from the Documentation: DesktopTextArea — Xojo documentation :slight_smile:

I dont want the last lines to the top of the text area.
I want that the 5-6 last lines of the text (depending of the text area height) be displayed with the last line at the bottom.
With ‘Zon_dial.VerticalScrollPosition = 100000’ (I have far less than 100000 lines into the text) the scrollbar dont go to the thumb bottom but to the middle.
In fact I expect that the text area work like a console screen…

Don’t do that. Use AddText as has been mentioned. Also use EndOfLine instead of chr(10).

You can also keep your own count of the number of lines in the textarea, and set the VerticalScrollPosition to a number a bit greater than that.

If you put all this into a method that you call to display a user message, you can simplify your code everywhere. You could also display coloured messges, too.

I do that.
This is the “message” routine

Blockquote

Zon_dialog.AddText (text +nl)
nbdiachar = nbdiachar + len(text)
Zon_dialog.Refresh
Zon_dialog.VerticalScrollPosition = Zon_Dialog.LineNumber(nbdiachar)

Blockquote

Using chr(10) or EndOfLine dont change anything.
If I add one line at a time with user action between this seems to work.
But as soon I add several messages (each one with a call to this routine) the scrollbar dont go to the bottom and stay at the middle.

1 Like