0

Im working with SWT StyledText to display data to the user in one part of the window. In another part I have a graph, over which I slide my mouse pointer. As I slide my mouse over a point in the graph, it highlights the corresponding entry in the StyledText Area.

I want my textArea to automatically scroll to the newest change, so I am using .setTopIndex(). To determine the index I need to be able to look at which entries in the textArea changed from not highlighted to highligted, I use the following (to check if my styleRange changed):

styledText.getStyleRangeAtOffset(offset)

So far my program functions correctly. My next check is:

styledText.getStyleRangeAtOffset(offset).isUnstyled 

or

styledText.getStyleRangeAtOffset(offset).foreground 

or something like that. Here enters the problem. When I call any of these I get a nullPointerException.

Valkyrie
  • 108
  • 13
  • the return value of getStyleRangeAtOffset is null, maybe you offset is wrong – deterministicFail Dec 11 '13 at 13:21
  • Does your usage meet the conditions under which getStyleRangeAtOffset would return null? http://help.eclipse.org/helios/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/custom/StyledText.html#getStyleRangeAtOffset(int) – Charlie Dec 11 '13 at 13:25
  • You should post `getStyleRangeAtOffset` method too. – Ioan Dec 18 '13 at 08:06

1 Answers1

0

Thank you for all the pointers :) after some debugging I discovered that the unedited styleRange is null. That explains the nullPointer I kept on receiving

Valkyrie
  • 108
  • 13