Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking required JTextFields

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JDialog that contains about 6 JTextFields which are all required
fields. It also contains an OK button and a Cancel button. I want to disable to OK button until all required JTextFields have had data entered.
Does someone know a way to do this?

Thanks.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write a method :

areNoFieldsEmpty()

create a DocumentListener. In all the methods do this :

okBtn.setEnabled(areNoFieldsEmpty());

Register your document listener with all 6 textfields.

Job's a good 'un.
D.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic