Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2005

Tip: Looking for answers? Try searching our database.

JTextArea not producing events

Thread view: 
Roedy Green - 29 Dec 2005 01:07 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.