Element map = view.getBuffer().getDefaultRootElement(); int startLine = map.getElementIndex(textArea.getSelectionStart()); int endLine = map.getElementIndex(textArea.getSelectionEnd()) + 1; int height = textArea.getToolkit().getFontMetrics(textArea .getFont()).getHeight(); int scrollHeight = ((endLine - startLine) + 1) * height; int viewHeight = view.getSize().height; Rectangle rect = new Rectangle(0,startLine * height - ((viewHeight - scrollHeight) / 2),0,viewHeight); rect.height = Math.min(viewHeight,textArea.getSize().height - rect.y); textArea.scrollRectToVisible(rect);
int line = textArea.getCaretLine(); int offset = textArea.offsetToX(textArea.getCaretLine(), textArea.getCaretPosition() - textArea .getLineStartOffset(textArea.getCaretLine())); textArea.scrollTo(line,offset);
	public void actionPerformed(ActionEvent evt)	{		View view = getView(evt);		JEditTextArea textArea = view.getTextArea();		Element map = view.getBuffer().getDefaultRootElement();		int startLine = map.getElementIndex(textArea.getSelectionStart());		int endLine = map.getElementIndex(textArea.getSelectionEnd()) + 1;		int height = textArea.getToolkit().getFontMetrics(textArea			.getFont()).getHeight();		int scrollHeight = ((endLine - startLine) + 1) * height;		int viewHeight = view.getSize().height;		Rectangle rect = new Rectangle(0,startLine * height			- ((viewHeight - scrollHeight) / 2),0,viewHeight);		rect.height = Math.min(viewHeight,textArea.getSize().height			- rect.y);		textArea.scrollRectToVisible(rect);	}