J
Jason Cavett
I'm attempting to handle focus on a JTextField. Basically, when the
user tabs to the text field, I want all the text to be highlighted.
When the user uses the mouse to give the JTextField focus, I just want
the field to behave normally.
I attempted to add a FocusListener (see below), but it doesn't seem to
be working the way I intended. Can anybody provide some insight?
(Maybe I should use something other than a FocusListener?)
private FocusListener focus = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
if (/*Not sure of the check to put in here. Tried a number of
things that haven't worked.*/) {
selectAll();
}
}
@Override
public void focusLost(FocusEvent e) {
}
};
user tabs to the text field, I want all the text to be highlighted.
When the user uses the mouse to give the JTextField focus, I just want
the field to behave normally.
I attempted to add a FocusListener (see below), but it doesn't seem to
be working the way I intended. Can anybody provide some insight?
(Maybe I should use something other than a FocusListener?)
private FocusListener focus = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
if (/*Not sure of the check to put in here. Tried a number of
things that haven't worked.*/) {
selectAll();
}
}
@Override
public void focusLost(FocusEvent e) {
}
};