This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

text event

 
kelly devon
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am writing a program whereby i'll have twoo text fields
and once i enter a text in one text field, i want it to display in the other textfield without me clicking on any buttons, the only button there will be
the exit button.in the textvaluechanged method of the textfield, how do i get it to return true if there is something written in the textfield?
help pls this textListener is kinda new to me. how do use the actionlis
tener with getting a value in the JTexxfield or know when something has been typed in the field?
 
Joe Ess
Bartender
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the text to appear in both fields as it is being typed, you will want a Key Listener. Text Listener informs you that a field has been changed once the change is complete. Take a look at the Java Tutorial chapter on How to Write a Key Listener for examples.
 
satya kalyani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
get document of first textfield and set it as the document to the second textfield, something similar to the code below

JTextField text1 = new JTextField("Test");
JTextField text2 = new JTextField();
text2.setDocument(text1.getDocument());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic