Reputation: 299
I've got problem with SWT StyledText scrollbars. I've added listeners to both (horizontal and vertical) scrollbars of my styled text:
styledText.getHorizontalBar().addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
//Some action
}
});
styledText.getVerticalBar().addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
//Some action
}
});
My problem is that listeners that I've added react only when user moves a scrollbar using mouse. If for example only part of the styledText is visible and user types in some text, which causes change in visible client area, than listeners are not informed about a change.
My question is - is it possible to somehow listen to changes on visible client area of the styled text?
Upvotes: 2
Views: 579
Reputation: 111142
The JFace TextViewer
(which uses StyledText
) supports an IViewportListener
which does what you want.
If you don't want to use JFace then you can duplicate how TextViewer
calls its listener. It listens for control resize, key release, key pressed, mouse up, and widget selected. It then checks if StyledText.getTopPixel()
has changed.
Upvotes: 4
Reputation: 156
You are adding listeners specifically to the object returned by getHorizontalBar(), that is why nothing is happening when the user inputs text. Try adding a listener to getContent() as well. Something along the lines of:
styledText.getContent().addTextChangeListener (new TextChangeListener() {
//events
};
Upvotes: 1