Don't have a clue what's causing this from your description but
here's a couple of ideas for finding out what's going on:
- Subclass the JTextField and override processKeyEvent with:
protected void processKeyEvent(KeyEvent e) {
System.out.println("processKeyEvent : " + e);
super processKeyEvent(e);
}
- Add a listener for key events to the AWT Event Queue:
Toolkit.getDefaultToolkit().addAWTEventListener(
new AWTEventListener() {
public void eventDispatched(AWTEvent event) {
System.out.println("Listener : " + event);
}
},
AWTEvent.KEY_EVENT_MASK);
Also have you tried implementing keyTyped in your KeyListener?
A different approach would be to add a DocumentListener to the
JTextField's Document. That would let you monitor changes to
the JTextField's contents instead of just keystrokes (some of
which may not be relevant).
Dave Wathen
Canzonet Limited
http://www.canzonet.com
mailto:[EMAIL PROTECTED]
-----Original Message-----
From: lehmann2 [mailto:[EMAIL PROTECTED]]
Sent: 23 May 2002 13:44
To: Dave Wathen
Cc: max; [EMAIL PROTECTED]
Subject: Re: keyboard focus
the characters typed appear in the textfield. the only one that do not cause
any
r�action are keys such as backspace, enter, del, tab ...
And the listener's methods are not called.
G.
Dave Wathen a �crit :
> When you say nothing happens do you mean that your listener
> is not being notified or really nothing so the characters
> typed don't appear in the textfield either?
>
> Dave Wathen
> Canzonet Limited
> http://www.canzonet.com
> mailto:[EMAIL PROTECTED]
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of lehmann2
> Sent: 23 May 2002 08:55
> To: max
> Cc: [EMAIL PROTECTED]
> Subject: Re: keyboard focus
>
> Hi Max and thanks for your answer.
>
> max a �crit :
>
> > > I have a problem with the JTextFields in my IHM.
> >
> > What does IHM mean ?
>
> oups! sorry, IHM is the frensh for GUI ...
>
> >
> >
> > I THINK i know what you are asking for - but im not sure. Can you give a
> > short code-example of what it is you are trying to do ?
> >
> > /max
>
> Well,
> I have a JPanel in a JFrame that contains a JTextField and JButtons.
> Here is a part of my code:
>
> JTextField txtName = new JTextField();
> txtName.addKeyListener(new KeyAdapter() {
> public void keyPressed(KeyEvent e) {
> System.out.println("KeyPressed");
> enableButtons()
> };
> public void keyReleased(KeyEvent e) {
> enableButtons()
> System.out.println("KeyReleased");
> };
> private void enableButtons() {
> buttonOK.setEnabled(true);
> cancelBtn.setEnabled(true);
> }
> });
>
> As you can see, I just want to enable buttons when a key is typed in the
> textfield.
> I implemented both keyPressed() and keyReleased() because I had ever
> observed
> that when I type a key, it often happens that only one of these two
methods
> is called ... so that way I am sure that the enablebuttons() method is
> called
> ... but my problem is not here.
>
> In a general way, when I type a key, the buttons are properly enabled, and
> traces are OK, but sometimes (I haven't found why), it is as if the
> textfield
> had lost its listener: nothing happens when a key is typed. If I leave the
> panel and then come back to it ( My frame has a central panel in witch can
> be
> loaded my textfield panel or another one), sometimes the listener "comes
> back" but it is not garanteed.
>
> I have read in swing doc that the textfield has to be visible and to have
> the
> keyboard focus so that its keylistener is activated; I added a focus
> listener
> to the textfield to trace when the focus is gained and lost, and I could
see
> it did had the focus ... that is why I thought that having the keyboard
> focus
> was not the same as having the focus detected by the listener ... now, I
> Know
> my supposition was wrong, so I am absolutly impowerished... <:(
>
> Do you have any idea?
>
> greetings,
> G.
>
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing