public void select ( int pos ) { if ( pos >= 0 ) { try { int line = getLineOfOffset ( pos ) ; Rectangle rect = modelToView ( pos ) ; if ( rect == null ) { select ( pos , pos ) ; } else { try { Rectangle nrect = modelToView ( getLineStartOffset ( line + 1 ) ) ; if ( nrect != null ) { rect = nrect ; } } catch ( Exception exc ) { } JViewport vp = ( JViewport ) getParent ( ) ; Rectangle viewRect = vp . getViewRect ( ) ; if ( viewRect . y + viewRect . height > rect . y ) { // need to scroll up select ( pos , pos ) ; } else { // need to scroll down rect . y += ( viewRect . height - rect . height ) / 2 ; scrollRectToVisible ( rect ) ; select ( pos , pos ) ; } } } catch ( BadLocationException exc ) { select ( pos , pos ) ; //exc.printStackTrace(); } } }
Moves the selection to the given offset .