• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

text event

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
reply
    Bookmark Topic Watch Topic
  • New Topic