mchr
mchr

Reputation: 6251

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

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?

Upvotes: 3

Views: 2963

Answers (1)

mchr
mchr

Reputation: 6251

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);

Upvotes: 2

Related Questions