> The default behaviour when focus passes to a JTextField appears to be
> for the cursor to go to the end of the text.
>
> I would like to set it up so that all the text is selected and typing
> anything will erase the old text.
If you have a member field like
private JTextField text = new JTextField();
you can add a focuslistener to selected the text like
text.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
text.selectAll();
}
});
If you have a lot of text fields, you can of course do this from a
central builder, a visitor or in a subclass constructor.
Regards,

Signature
Filip Larsen
Alan Rubin - 23 Aug 2004 14:48 GMT
> private JTextField text = new JTextField();
>
[quoted text clipped - 5 lines]
> }
> });
Thanks. What I have written in focusGained is:
((JTextField)e.getComponent()).selectAll();
Alan
> I would like to set it up so that all the text is selected and typing
> anything will erase the old text.
In addition to the answer you got, this was IIRC a change in the
Windows L&F because Windows controls stopped automatically selecting
text on focus in W2k or so.