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.moveCaretPosition(cur); } catch (BadLocationException ble) {  }
if (t != null) { int offs = t.getCaretPosition() + 1;  if(offs <= t.getDocument().getLength()) { Caret c = t.getCaret(); c.moveDot(offs); try { c.setMagicCaretPosition(t.modelToView(offs).getLocation()); } catch(BadLocationException ble) {  } } }
      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.moveCaretPosition(cur);       }       catch (BadLocationException ble)       {         // Nothing to do here       }      }