Java SWT StyledText event to detect when the Control autoscrolls to show cursor position

241 Views Asked by At

For a RCP text editor a Styledtext is used.

The StyledText Background-Image and Text need to be scrolled all at once.

How can be detected the event of autocroll? if exists.

For example: If the user press the END_KEY and the line in which the caret is located is is longer than the size of the StyledText Control area, then the Control autoscrolls to show the caret position. The same happeds if the user press the LEF_ARROW and the cursor is at the beggining of line and the previous line has a lenth greater than the control size.

So when autoscroll is detected, a listener can redrawn the background accordingly.

Up to date the solution found is to write listeners for each event which produced an autoscroll. i.e. write events for:

st.addCaretListener(new CaretListener (){...}; st.addListener(SWT.Modify, new Listener() {...}; ... st.addKeyListener(){...}; st.addMouseListener(){...};

So inside of each event write code to paint the background image. Whith a listener to be notified when the controls scrolls itself, code shall be more efficient.

Thanks in advance

0

There are 0 best solutions below