How to identify on which component the focus is currently residing

A

arun.viswanath

Hi,

I'm have n JTextField and one "Ok" and "Cancel" button in my form.

I want to validate the date entered in TextField but my validation is
depends on the component focus.

Say If I press the Cancel Button I dont want to validate the data in
Textfield.

So before validation I want to get the current focus i.e the focus is
on which component, Based on it I will either validate or not validate
my text field data.

Thanks in Advance,
Arun.
 
E

Evans

Hi,

I'm have n JTextField and one "Ok" and "Cancel" button in my form.

I want to validate the date entered in TextField but my validation is
depends on the component focus.

Say If I press the Cancel Button I dont want to validate the data in
Textfield.

So before validation I want to get the current focus i.e the focus is
on which component, Based on it I will either validate or not validate
my text field data.

Thanks in Advance,
Arun.

You don't need any focus on the textfield to validate the value
entered in your form.
Just call the textfield.getText() method to indicate that you want the
value entered in the textfield. Then, do whateve you want with the
returned value.

Evans Anyokwu
http://jroller.com/evans
 
M

Mark Space

Hi,

I'm have n JTextField and one "Ok" and "Cancel" button in my form.

I want to validate the date entered in TextField but my validation is
depends on the component focus.

Say If I press the Cancel Button I dont want to validate the data in
Textfield.

So before validation I want to get the current focus i.e the focus is
on which component, Based on it I will either validate or not validate
my text field data.

So, I don't think the focus matters here.

If I understand correctly, you have two buttons, OK and Cancel. What
you want to do is add an ActionListener to each button.

The OK ActionListener verifies the form and then closes the form window
or whatever, and returns the validated data (I'd guess).

The Cancel ActionListener just closes the form window and returns a
"nevermind" result to the caller. It skips validation.

Adjust to taste.

<http://java.sun.com/docs/books/tutorial/uiswing/components/button.html>

That will show you how to use a button with an action listener. If you
need more help, please post up a simple, complete example program so we
can see what you are doing and offer some more specific advice.
 
A

arun.viswanath

So, I don't think the focus matters here.

If I understand correctly, you have two buttons, OK and Cancel.  What
you want to do is add an ActionListener to each button.

The OK ActionListener verifies the form and then closes the form window
or whatever, and returns the validated data (I'd guess).

The Cancel ActionListener just closes the form window and returns a
"nevermind" result to the caller. It skips validation.

Adjust to taste.

<http://java.sun.com/docs/books/tutorial/uiswing/components/button.html>

That will show you how to use a button with an action listener.  If you
need more help, please post up a simple, complete example program so we
can see what you are doing and offer some more specific advice.

Hi,

Thanks for your reply, But my problem is not the same as u understood.

Let me explain it , Im having One TextField and One Button(Bypressing
it can set some constant value in the Textfield) on a pane. (The
Botton is associated with the Jtextfield).
Like above I have 5 to 6 pane in dialog box with one "Ok" and one
"Cancel" button.

My problem I want to verify the Textfield data when the textfield lose
it focus.
My verification should be done only if I'm clicking the another
TextField or Button associate with other textfield or pressing the Ok
button.
And whenever I'm pressing the associate button my textfield data
should not validate , instead my the value in associate textfield
should be replaced by the constant value
and whenever the "Cancel" is pressed the screen(dialogbox) should go
of..

Please let me know if you have some more queris.

Thanks in Advance,
Arun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top