File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
I agree. Here's the link:
subject: Checking required JTextFields
It's not a secret anymore!