Error and Tab key problem

I installed Java Eclipse.  During my training it is normal for when entering information in a form you press enter and it goes from one field to another.  However, I found that only the tab key works and when the tab key is used no event handling takes place.  However, when the enter is press it does the event handling but does not go the next field.  Is there a setting in Eclipse or Java that can correct this key problem.
Vanavah EdwardsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
If yoiu are talking about the form in your java program which yiu are debugging with eclipse, then it has nothing to do with Eclipse. This is stndard Java Jtextfield behavior - it triggers ActionEvent only on Entet. It does not trigger it on tab or any otehr key entered in the texfield
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:
If you want to track any other keys typed in the textfield - use KeyListener
0
for_yanCommented:
KeyListener will allow you top analyze the input of any character in JtextFiekd and take any action you requre
0
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

for_yanCommented:
ActionEvent is generic event - eeac element generate it on its most common function - such as enter for textfield. KeyEvent is more specific for tex componens and allow much moredetailed analysis and speific response for JtextField
0
Vanavah EdwardsAuthor Commented:
What I mean is that on any of the fields when the enter key is press it does do from one field to the next whether it is blank or not.  Even demo programs..  This is what has been prohibiting my progress in event handling.
0
for_yanCommented:
That is normal behavior. How does it oprhibit ?
In your event handler you just read text and if noithing is entered take appropriate action - usually say just return
0
for_yanCommented:
The normal way to deal with mutitextfield form is to provide submit button and let the user to enter the fileds in any oirder he wants (using tabs or enters or anythng) and not listen to events from these textelements. After the user clicks the submit button yiu may analyze and if sone crucial texyfiled is lacking info or if the inpuit is wrong - raise the errror message
0
Vanavah EdwardsAuthor Commented:
Isnt' is normal function for when you press the enter key on a text field to move from one field to the next.  Whilst with combo box and other components it is tab.
0
for_yanCommented:
The tab is normal way to move from one textbox to the next. But not all users use it - most are jus using mmouse clicking. So it is better not to listen to events from textfields unless for some spoecial reason
0
Vanavah EdwardsAuthor Commented:
If this is normal for the tab key to do this in java instead of the enter key like other languages.  I would like to trigger if the tab key was press so that I can test what was entered.
0
for_yanCommented:
Tab is normal everywhere especially on the web - and that becomes the standard
0
Vanavah EdwardsAuthor Commented:
The reseaion I was testing what was entered is that I have to display infomation in the fields from a database as the user progress so as to avoid wrong data entry.  So I would then have to test for events witht he tab.  How do I do that?
0
Vanavah EdwardsAuthor Commented:
What type of listener does that?  I already know how to write the event handling routine.  Is the tab key progressive testing that I have to get solve.
0
for_yanCommented:
If you want ti trak in more detail yoiu can use keylistener as I mentioned aboive. For what you want maybe yoiu want rather to use FoicusLisrener and that will triger even when your textbox loses focus.
However, if this is not absolutely necesary I recommend not to do it but rather analluyeze the whole form as I mentioned above - focusListener and keylistener sometimes are difficult to debug
And if they are not well deb ugged they will cause probklems to the user.
0
Vanavah EdwardsAuthor Commented:
That is the solution - focusListener.  Now if after I test and the data is invalid.  How do I set back focus to the component.
0
for_yanCommented:
There are methods requestfocus or requestfocusinwindow for that purpoose.  Sstill it would peob ably be a big pain, beter redesign so that user presses tge button when he is done with form or poart of thw form
0
Vanavah EdwardsAuthor Commented:
I tried the focuslistener and it works.  However, I am now unable to getText or getSelectedText as the focuslost method does not have these method.  So what should I do?
0
Vanavah EdwardsAuthor Commented:
Thank you very much.  I tried the component.requestFocust() method and it works.  It sets back the focus and stays on that field.  However, I have the final problem.  I am now unable to getText or getSelectedText as the focuslost method does not have these method.  So what should I do?
0
Vanavah EdwardsAuthor Commented:
I am so happy for this solution.  Now I can test when I lost focus from a component and If the data is invalid I can set back focus on that object.  I can not do a progressive test.  I just need to get the text entered and I am done.
0
Vanavah EdwardsAuthor Commented:
I mean I can now do a progessive test which is what I wanted all along.
0
for_yanCommented:
Look, getText is not connected to what kind ofevent you are tracking - this is a methoid of yiur textfield no matter where you use it - yuy can use it in any place in any methid; make suree that tetxfield is accessible (instance variable, not local)
0
Vanavah EdwardsAuthor Commented:
Everything works.  However, can you decipher what is wrong with focuslost method.  When I tested for the source it works. But when I test for the source and if the field is null it doesn't work.  The code seem correct.  
public void focusLost(FocusEvent e) {
	    	if(e.getSource()==tf1 && tf1.getText().equals(null)) {
				  System.out.println("This field cannot be blank");
				  tf1.requestFocus();
			  }

		  }

Open in new window

0
for_yanCommented:
I told you many times don't write this - e.getSource()==tf1
Only equals should be used

0
for_yanCommented:

I think that would be incorrect:
tf1.getText().equals(null)

tf1.getText().trim().length() == 0  will test for no input in te text filed
0
Vanavah EdwardsAuthor Commented:
Problem solved.  it works.  You are good.  I will now close off this session and go and work.  Thank you very much for your time and patience.
0
Vanavah EdwardsAuthor Commented:
I forgot to add.  This also solves the problem with auto-completion session that we were discussing in another session.  This focus listener was the solution all along.
0
for_yanCommented:
well, let's hope it works fine for you
in my experiece it sometimes fires at the moments inconvenient for the user
0
Vanavah EdwardsAuthor Commented:
Even though ithat happens.  It is only when the combobox loses focus is when the user has finish his selection, isn't it?  Therefore, that is when I shall test.
0
for_yanCommented:
Well, sounds OK theoretically.
In practice I usually ended up going away from it.
It is all a matter of testing - and if it is convenient then fine; I usually had some situation which I didn't like - it generated some events
at unwanted times.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.