tags:

views:

177

answers:

1

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?

A: 

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);
mchr
Actually with a StyledText control this is all unnecessary as appendText does not auto scroll the control. However, the above code will work for a Text control.
mchr