File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes getting action from field without pressing enter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting action from field without pressing enter" Watch "getting action from field without pressing enter" New topic
Author

getting action from field without pressing enter

Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
I have some JTextFields and I want to be able to capture user action without relying on the user to press enter. most people I see using my program fill in the fields and move on to the next one without pressing enter at each one. And I don't want to put in a button. Can i get the action to kick in just by the user typing in a value?
Thanks!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You can create a FocusListener for the JTextFields and then on something like focusLost() do whatever you need to do.


GenRocket - Experts at Building Test Data
Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Thanks, that helps alot. Although now I get an error:
Board.handler is not abstract and does not override abstract method focusGained(java.awt.event.FocusEvent) in java.awt.event.FocusListener
And here's a bit of code...
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

When implementing an interface you are required to override all public methods that exist in the interface. For FocusListener there is focusGained() and focusLost(). You don't have to do anything in either method, but you have to at least implement the method itself.
I use the MouseListener interface a lot and it has 4 methods you have to implement. I usually only use 1 of them, so the other ones just all sit there empty.
[ April 26, 2004: Message edited by: Gregg Bolinger ]
Helen Crosbie
Greenhorn

Joined: Mar 11, 2003
Posts: 26
You can get round this by using the FocusAdapter class. This implements the FocusListener for you, but with empty methods.
This means you just need to subclass it and write the methods that you're interested in.
Helen Crosbie
Greenhorn

Joined: Mar 11, 2003
Posts: 26
You can get round this by using the FocusAdapter class. This implements the FocusListener for you, but with empty methods.
This means you just need to subclass it and write the methods that you're interested in.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting action from field without pressing enter