code: public int getCharOffsetXElem(int pos)
      {
          if (text != null)
          {
              FontMetrics fm = g.getFontMetrics();
              if (pos <= textStart)
                  return 0;
              else if (pos > textStart && pos < textEnd)
                  return stringWidth(fm, text.substring(textStart, pos));
              else
                  return stringWidth(fm, text.substring(textStart, textEnd));
          }
          else
              return 0;
      }
docs: Computes the X pixel offset of the given character of the box text. The character position is specified within the
  whole source text node.
  @param pos the character position in the string absolutely within the source text node (0 is the first character in the node)
  @return the X offset in pixels or 0 when the position does not fit to this box