How do I convert an (x,y) MouseEvent position to an offset in a JTextPane?

Sandip Chitale

public int viewToModel(Point pt)

Converts the given place in the view
coordinate system to the nearest
representative location in the model. The
component must have a positive size for this
translation to be computed (i.e. layout
cannot be computed until the component has
been sized). The component does not have to
be visible or painted.

pt - the location in the view to translate

the offset >= 0 from the start of the document, or -1 if the component does not yet have a positive size.