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