• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

getting action from field without pressing enter

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic