| 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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
You can create a FocusListener for the JTextFields and then on something like focusLost() do whatever you need to do.
|
 |
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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
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.
|
 |
 |
|
|
subject: getting action from field without pressing enter
|
|
|