Re: TextListener Event
- From: "JediJ" <jfalter@xxxxxxxxx>
- Date: 26 Jul 2005 06:32:03 -0700
It looks like your still looking for a little help, so I'll chime in.
I would add a focus listener to your JTextField.
This is fairly straight forward.
First you need to import the Listener and the Event that is associated
with it...
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
The FocusListener is an interface, so you must implement all of its
methods, even if you arent going to use them for anything.
There are quite a few different strategies for doing the Listeners.
For something like this, I would make it an inner class. Something
like:
class FocusHandler implements FocusListener
{
public void focusGained(FocusEvent fe)
{
}
public void focusLost(FocusEvent fe)
{
}
}
In the constructor of your GUI class, create an instance of your
FocusHandler:
FocusHandler myFocusHandler = new FocusHandler();
then add it to your components...
yourComponent.addFocusListener(myFocusHandler);
The last thing you will need to do is add the logic to the methods of
the FocusHandler class. You can find out what component has the Focus
using fe.getSource();
So you would do something like
if(fe.getSource() == myTextField)
{ //disable/enable stuffs}
else if(fe.getSource() == myComboThingy)
{ //disable/enable other stuffs}
Hope that helps.
.
- Follow-Ups:
- Re: TextListener Event
- From: JediJ
- Re: TextListener Event
- References:
- TextListener Event
- From: Ron Barnhart
- Re: TextListener Event
- From: Andrew Thompson
- Re: TextListener Event
- From: Ron Barnhart
- Re: TextListener Event
- From: Andrew Thompson
- Re: TextListener Event
- From: Thomas Weidenfeller
- TextListener Event
- Prev by Date: Re: Fading window problem
- Next by Date: Re: TextListener Event
- Previous by thread: Re: TextListener Event
- Next by thread: Re: TextListener Event
- Index(es):