javaswteclipse-rcpjface

How to enable autoscroll for a StyledText Component


I'm using StyledText component which behaves somewhat similar to the popular eclipse IDE console view, (which appends the log), but here, in my StyledText component the scroll-lock is enabled. I mean for each line appended to the StyledText, the vertical scroll bar position remains constant. Below image reflects the behavior:

enter image description here

As an attempt I tried like this:

StyledText declaration

StyledText styledText = new StyledText(parent, SWT.V_SCROLL); 

//other relevant code here

styledText.addListener(SWT.SCROLL_LOCK, new Listener() {
            @Override
            public void handleEvent(Event event) {
                // TODO Auto-generated method stub
                event.doit=false;// i tried true also doesn't work
            }
        }) ;

How do I disable (scroll lock)? show the last line appended and with the scroll(vertical) bar position at the bottom?


Solution

  • I'd try to set the caret at the end of the text after appending if it was at the end of the text before appending. This would allow the user to stop autoscrolling by setting the caret somewhere else and to re-enable autoscrolling by setting the caret at the end.