View rootView = c.getUI().getRootView(c); Rectangle r = c.modelToView(offset); int offs = c.viewToModel(new Point(x, r.y)); int pos = rootView.getNextVisualPositionFrom(offs, Position.Bias.Forward, SwingUtilities.calculateInnerArea(c, null), SwingConstants.NORTH, new Position.Bias[1]); return pos;
int offs = getRowStart(c, offset);  if(offs == -1) return -1;   Point pt = c.modelToView(offs-1).getLocation();  pt.x = x;   offs = c.viewToModel(pt);    int offsX = c.modelToView(offs).getLocation().x; int offsXNext = c.modelToView(offs+1).getLocation().x;   if (Math.abs(offsX-x) < Math.abs(offsXNext-x)) return offs; else return offs+1;
  public static final int getPositionAbove(JTextComponent c, int offset, int x)    throws BadLocationException  {    View rootView = c.getUI().getRootView(c);    Rectangle r = c.modelToView(offset);    int offs = c.viewToModel(new Point(x, r.y));    int pos = rootView.getNextVisualPositionFrom(offs,                                                 Position.Bias.Forward,                                    SwingUtilities.calculateInnerArea(c, null),                                                 SwingConstants.NORTH,                                                 new Position.Bias[1]);    return pos;  }