Ok, I'm ready to toss this thing across the room. Here's what I'm
trying to accomplish, greatly simplified:
I have a screen with several text fields. I want to validate the
entry in each text field when the user tabs out of it to the next one
(some fields are required). If they enter an invalid entry or leave
it blank, I want to display a pop-up in the form of a
JOptionPane.sho wMessageDialog to inform them of the problem, then
reset focus to the invalid field.
Here's the problem: fields a, b, and c are all validated this way,
and are sequential in the focus order. In a new screen, if the user
enters an invalid value into field a, field b briefly gets the focus
from the tab key, and in the course of popping up the box and
resetting focus to field a, field b loses this brief focus, gets
validated because of this, and I end up with two and sometimes three
pop-up boxes that I don't want. I am using isTemporary(); without it
I end up in an infinite loop of popups. Here's a greatly simplified
overview of my focusLost function as it stands now:
public void focusLost(Focus Event fe)
{
if(!fe.isTempor ary()) {
if(fe.getsource == fieldA) {
// do validation here
if(valid) { // do nothing, allow to go on
}
else {
fieldA.requestF ocus();
JOptionPane.sho wMessageDialog. ..;
}
}
if(fe.getsource == fieldB) {
// do validation here
if(valid) { // do nothing, allow to go on
}
else {
fieldB.requestF ocus();
JOptionPane.sho wMessageDialog. ..;
}
}
// etc etc for more validated fields
}
I also want to NOT perform the focus lost validation if the user
clicks a "clear" button that clears out all the data on the screen.
It won't let the user do this because when you click the button it
validates the field you were in, and if it's not valid you get the
dialog popup.
I've spent two days trying ideas and I'm still plagued by these
"phantom" popups. If anyone has encountered this issue before and has
any ideas, please post a reply if you have the time to help.
Thanks all.
trying to accomplish, greatly simplified:
I have a screen with several text fields. I want to validate the
entry in each text field when the user tabs out of it to the next one
(some fields are required). If they enter an invalid entry or leave
it blank, I want to display a pop-up in the form of a
JOptionPane.sho wMessageDialog to inform them of the problem, then
reset focus to the invalid field.
Here's the problem: fields a, b, and c are all validated this way,
and are sequential in the focus order. In a new screen, if the user
enters an invalid value into field a, field b briefly gets the focus
from the tab key, and in the course of popping up the box and
resetting focus to field a, field b loses this brief focus, gets
validated because of this, and I end up with two and sometimes three
pop-up boxes that I don't want. I am using isTemporary(); without it
I end up in an infinite loop of popups. Here's a greatly simplified
overview of my focusLost function as it stands now:
public void focusLost(Focus Event fe)
{
if(!fe.isTempor ary()) {
if(fe.getsource == fieldA) {
// do validation here
if(valid) { // do nothing, allow to go on
}
else {
fieldA.requestF ocus();
JOptionPane.sho wMessageDialog. ..;
}
}
if(fe.getsource == fieldB) {
// do validation here
if(valid) { // do nothing, allow to go on
}
else {
fieldB.requestF ocus();
JOptionPane.sho wMessageDialog. ..;
}
}
// etc etc for more validated fields
}
I also want to NOT perform the focus lost validation if the user
clicks a "clear" button that clears out all the data on the screen.
It won't let the user do this because when you click the button it
validates the field you were in, and if it's not valid you get the
dialog popup.
I've spent two days trying ideas and I'm still plagued by these
"phantom" popups. If anyone has encountered this issue before and has
any ideas, please post a reply if you have the time to help.
Thanks all.
Comment