Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting action from field without pressing enter

 
Kate Zoy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a FocusListener for the JTextFields and then on something like focusLost() do whatever you need to do.
 
Kate Zoy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic