Run the little SSCCE below and you will not get any events at the
InputMethodListener. Why not? How are you supposed to detect a
change? It won't let you use an ActionListener or a TextListener.
// sample use of a JTextArea
import java.awt.Color;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JTextArea;
// ...
public class TestJTextArea
{
/**
* Debugging harness for a Frame
*
* @param args command line arguments are ignored.
*/
public static void main ( String args [] )
{
final JFrame frame = new JFrame();
// The user hitting enter inserts a \n character into the text.
final JTextArea textarea = new JTextArea( "this is a test\nof
multiline." );
textarea.setBackground( Color.BLACK );
textarea.setForeground( Color.YELLOW );
textarea.setFont( new Font( "Dialog", Font.BOLD, 15 ));
textarea.setEnabled( true );
textarea.setEditable( true );
textarea.addInputMethodListener( new InputMethodListener()
{
/**
* Invoked when the text
entered through an input method has changed.
*/
public void
inputMethodTextChanged( InputMethodEvent event )
{
System.out.println(
textarea.getText() );
}
/**
* Invoked when the caret
within composed text has changed.
*/
public void
caretPositionChanged( InputMethodEvent event )
{
System.out.println(
textarea.getCaretPosition() );
}
});
frame.add( textarea );
frame.setSize( 100, 100 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.validate();
frame.setVisible( true );
} // end main
}

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Michael Dunn - 29 Dec 2005 01:47 GMT
> Run the little SSCCE below and you will not get any events at the
> InputMethodListener.
> Why not?
from the api docs (addInputMethodListener)
"Adds the specified input method listener to receive input method events from this component.
A component will only receive input method events from input methods if it also overrides
getInputMethodRequests to return an InputMethodRequests instance."
> How are you supposed to detect a
> change? It won't let you use an ActionListener or a TextListener.
DocumentListener