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 / October 2004

Tip: Looking for answers? Try searching our database.

Capturing an event when a Textfield changes.

Thread view: 
Bilal Sallakh - 28 Oct 2004 19:31 GMT
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...


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.