This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Checking required JTextFields  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Checking required JTextFields  " Watch "Checking required JTextFields  " New topic

Checking required JTextFields

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
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?

Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
write a method :


create a DocumentListener. In all the methods do this :


Register your document listener with all 6 textfields.

Job's a good 'un.
It is sorta covered in the JavaRanch Style Guide.
subject: Checking required JTextFields