int lastVisible = textArea.getLineEndOffset( textArea.getFirstLine() + textArea.getVisibleLines() - textArea.getElectricScroll() - 1) - 1;
int lastVisibleLine = textArea.getFirstLine() + textArea.getVisibleLines(); if(lastVisibleLine >= textArea.getLineCount()) { lastVisibleLine = Math.min(textArea.getLineCount() - 1, lastVisibleLine); } else lastVisibleLine -= (textArea.getElectricScroll() + 1);  int lastVisible = textArea.getLineEndOffset(lastVisibleLine) - 1;
		public void actionPerformed(ActionEvent evt)		{			JEditTextArea textArea = getTextArea(evt);			int caret = textArea.getCaretPosition();			int lastLine = textArea.getLineEndOffset(				textArea.getCaretLine()) - 1;			int lastVisible = textArea.getLineEndOffset(				textArea.getFirstLine()				+ textArea.getVisibleLines()				- textArea.getElectricScroll() - 1) - 1;			int lastDocument = textArea.getDocumentLength();			if(caret == lastDocument)			{				textArea.getToolkit().beep();				return;			}			else if(caret == lastVisible)				caret = lastDocument;			else if(caret == lastLine)				caret = lastVisible;			else				caret = lastLine;			if(select)				textArea.select(textArea.getMarkPosition(),caret);			else				textArea.setCaretPosition(caret);		}