Text retrieval is lagging by one last character

The text I'm retrieving is always one character behind, how do I get the last character. The code below is not the entire method for obtaining text in a viewPort, but I'm positive this is where the problem is.

publicvoid keyPressed(KeyEvent e){

Rectangle r = scrollPane.getViewport().getViewRect();

double y = r.getY();

Point p =new Point(0,(int)y);

int n = TA.viewToModel(p);

boolean searching =true;

int negative = 0;//int to subtract lines

int lengthOfText;

String textInViewPort ="";

//load TA's test in a jtextarea so we have some workable methods

JTextArea jta =new JTextArea();

jta.setLineWrap(true);

jta.setText(TA.getText());

System.out.println("Text in viewPort "+jta.getText());

}

[1357 byte] By [jpeanuta] at [2007-11-27 2:40:58]
# 1
Thats right. You should never use a KeyListener for this. The Document has not yet been updated on a keyPressed event.There are higher level API's that you should be using. I don't know what your code is doing but you should probably be using a DocumentListener.
camickra at 2007-7-12 3:04:18 > top of Java-index,Desktop,Core GUI APIs...