Reputation: 5136
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?
Upvotes: 1
Views: 1684
Reputation: 1
This seemed to work perfectly for me. Can add a bunch of text, scroll down. Add more text, scroll up and down ending amount of data:
All I do is add the SWT.H_SCROLL,SWT.H_VSCROLL and SWT.BORDER to the styledText, which I dropped into the parent, ScrolledComposite: (best of luck to you!)
styledText = new StyledText(scrolledComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
===============================================
scrolledComposite = new ScrolledComposite(shlSheetMusicEntry, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setShowFocusedControl(true);
scrolledComposite.setBounds(10, 281, 638, 186);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
//styledText = new StyledText(scrolledComposite, SWT.BORDER);
styledText = new StyledText(scrolledComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
scrolledComposite.setContent(styledText);
scrolledComposite.setMinSize(styledText.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Upvotes: 0
Reputation: 29600
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.
Upvotes: 3