Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swt Text (SWT.MULTI) append text without scroll

Tags:

java

text

swt

I have a Java SWT GUI with a multiline Text control. I want to append lines of text to the Text control without affecting the position of the cursor within the text box. In particular, the user should be able to scroll and select text at the top of the Text control while new text lines are appended to the bottom.

Is this possible?

like image 231
mchr Avatar asked Aug 18 '26 08:08

mchr


1 Answers

I switched to using a StyleText control to fix flickering issues when adding text. With this control I found the following code fixed the issue of appending text without scrolling to the new location.

textOutput.setRedraw(false);
int scrollP = textOutput.getTopIndex();
Point selectionP = textOutput.getSelection();              
textOutput.append(traceText);
textOutput.setSelection(selectionP);
textOutput.setTopIndex(scrollP);
textOutput.setRedraw(true);
like image 148
mchr Avatar answered Aug 20 '26 22:08

mchr