*
The moose likes Swing / AWT / SWT and the fly likes focus listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "focus listener" Watch "focus listener" New topic
Author

focus listener

kajal sharma
Greenhorn

Joined: Oct 04, 2000
Posts: 22
use the following code to validate a user data in textbox and if the data do not match with
database then got the focus back to field with a dialog box.
But When yearfield get lost focus by pressing tab key then dialog box come up but my ok
does not make any effect .It is there as it is .I think it is losing focus that's why it come
up.please rectify my problem.
public void focusGained(FocusEvent fe){}

public void focusLost(FocusEvent e){
Object source1=e.getSource();
System.out.println(source1==yearfield);
if(source1==yearfield){
aa=yearfield.getText().trim();
System.out.println(aa);
if (aa.equals("__/__/____")){
JOptionPane.showMessageDialog( this, "This is a
dialog" );
yearfield.requestFocus();
flag14=false;
a2=""; }

}
}

When I am only using focus listener than Caret is blinking one time in time field and one
time in yearfield.

please help java gurus.
kajal sharma
Greenhorn

Joined: Oct 04, 2000
Posts: 22
Hello java gurus,
I tried this also but my focus is not returning on the same textfield why?
public void focusLost(FocusEvent e){
Object source1=e.getSource();
System.out.println(source1==yearfield);
if(source1==yearfield){
aa=yearfield.getText().trim();
System.out.println(aa);

if(e.isTemporary()){
yearfield.requestFocus();
return;}
else if (aa.equals("__/__/____"))
{

JOptionPane.showMessageDialog( this, "This is a dialog" );
flag14=false;
a2="";
}
}
}
James Beeson
Greenhorn

Joined: Apr 18, 2000
Posts: 18
Did you ever figure out a solution to this problem. I have had the exact same problem and no one seems to have provided a good solution.
Thanks
James
jbeeson@tahc.state.tx.us

Originally posted by kajal sharma:
Hello java gurus,
I tried this also but my focus is not returning on the same textfield why?
public void focusLost(FocusEvent e){
Object source1=e.getSource();
System.out.println(source1==yearfield);
if(source1==yearfield){
aa=yearfield.getText().trim();
System.out.println(aa);

if(e.isTemporary()){
yearfield.requestFocus();
return;}
else if (aa.equals("__/__/____"))
{

JOptionPane.showMessageDialog( this, "This is a dialog" );
flag14=false;
a2="";
}
}
}


------------------
eric moon
Ranch Hand

Joined: Nov 26, 2000
Posts: 133
I had a similar problem with requestFocus not getting to a new frame. Here's what I was given as a workaround:


<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>"Those who cast the votes decide nothing. Those who count the<BR>votes decide<BR>everything." <BR> -Joseph Stalin<HR></BLOCKQUOTE>
 
Don't get me started about those stupid light bulbs.
 
subject: focus listener
 
Similar Threads
Focus problem in 1.4_2 when JPopupMenu show is called
JComboBox and FocusListener
Focus issues among JTextField and Dialogs
focusListener wont work on JComboBox
FocusListener problem