Caret position in JTextField with selected text

I was trying to somehow set my caret position to 0 while I have all of the text selected in a JTextField. I have an event that will select all text upon receiving focus but it automatically puts the cursor at the end of the text field. But if i use the setCaretPosition(0) after that it will deselect all of the text.

txtProdLine.addFocusListener(new java.awt.event.FocusAdapter(){

publicvoid focusGained(java.awt.event.FocusEvent evt){

txtProdLine.selectAll();

}

});

I know I may be getting a little picky here but any help would be appreciated.

[795 byte] By [barichards21a] at [2007-11-27 7:44:47]
# 1
selectAll does it from 0 to end...How about calling select(txtProdLine.getLength(), 0);
bsampieria at 2007-7-12 19:25:24 > top of Java-index,Desktop,Core GUI APIs...
# 2

public void focusGained(java.awt.event.FocusEvent evt) {

txtProdLine.setCaretPosition(txtProdLine.getDocument().getLength());

txtProdLine.moveCaretPosition(0);

}

Michael_Dunna at 2007-7-12 19:25:24 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks Michael_Dunn, that worked perfectly. Not sure why I didn't see that moveCaretPosition method to begin with.
barichards21a at 2007-7-12 19:25:24 > top of Java-index,Desktop,Core GUI APIs...