Point p = t.modelToView(t.getCaret().getDot()).getLocation(); int cur = t.getCaretPosition(); int y = p.y; int length = t.getDocument().getLength(); while (y == p.y && cur < length) y = t.modelToView(++cur).getLocation().y; if (cur != length) cur--; t.setCaretPosition(cur);
int offs = Utilities.getRowEnd(t, t.getCaretPosition());  if (offs > -1) { Caret c = t.getCaret(); c.setDot(offs); c.setMagicCaretPosition(t.modelToView(offs).getLocation()); }
      public void actionPerformed(ActionEvent event)      {        JTextComponent t = getTextComponent(event);       try       {         Point p = t.modelToView(t.getCaret().getDot()).getLocation();         int cur = t.getCaretPosition();         int y = p.y;         int length = t.getDocument().getLength();         while (y == p.y && cur < length)           y = t.modelToView(++cur).getLocation().y;         if (cur != length)           cur--;         t.setCaretPosition(cur);       }       catch (BadLocationException ble)       {         // Nothing to do here       }      }