• 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

Compare Two Text fields in Swing

 
Ranch Hand
Posts: 60
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
I m new in swing first time working on swing,
i want to make a simple application for accounting, and my problem is that i checked

Debit and Credit entries.........means one time user enter debit or credit..........i have no idea which action i use for this
And how to compare it which field is filled and which is empty?.

please help me on this.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More details please.
What is ine time user enter debit or credit Does it mean the user can enter the amount only once?

JTextField#getText gives you the text inside that component. You can use it to perform your checks.
 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes sir you are right user enter one amount only one time Debit or Credit.


i want if user enter Debit and not able to enter Credit, if try to enter credit show message....its not valid only one entry at one time Debit or Credit...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
Easy on the "sir". We are all informal here

One way to do it is using a DocumentListener.
You provide a custom document listener to both the text fields. Once you figure out that the user has entered some value in field 1, you can disable the field 2.
 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnx Mark,
this solution also in my mind but problem is that if any user enter credit data in debit field by mistake, and when he want to correct this the credit field is disable......................

Any solutions we check textFields values on change event or key pressed event.....
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if the user deletes all data in field1 then field2 will be enabled and data can be entered there.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic