In this code fragment:
public class FrameLayers extends JFrame {
JTextField txtWidth = new JTextField();
public FrameLayers() {
txtWidth.addInputMethodListener(new InputMethodListener() {
public void caretPositionChanged(InputMethodEvent event) {
}
public void inputMethodTextChanged(InputMethodEvent event) {
System.out.Println("Hallo Welt");
}
}
}
}
I want to do something (here printling a string) when the user type
something in the JTextField.
The code doesn't work..
Why?
In the docs I read that getInputMethodRequests should be used
somewhere... How?
Thanks in advance...
Hegemony Cricket - 29 Oct 2004 00:52 GMT
I don't know much about InputMethodListener, but I've always
accomplished the same thing in the past by using a DocumentListener.
So, something like
txtWidth.getDocument().addDocumentListener( new DocumentListener()
{
public void changedUpdate(DocumentEvent e) { textChanged(e); }
public void insertUpdate(DocumentEvent e) { textChanged(e); }
public void removeUpdate(DocumentEvent e) { textChanged(e); }
private void textChanged(DocumentEvent e)
{
System.out.println( "Hallo Welt" );
}
} );
> In this code fragment:
>
[quoted text clipped - 24 lines]
>
> Thanks in advance...