How to enable autoscroll for a StyledText Component

こ雲淡風輕ζ 提交于 2019-12-11 13:16:49

问题


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:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/8615475/how-to-enable-autoscroll-for-a-styledtext-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!