wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Checking required JTextFields  " Watch "Checking required JTextFields  " New topic
Author

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?

Thanks.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Checking required JTextFields
 
Similar Threads
Hiding a JComboBox's popup window
simulating a button press
How to know which component has the current focus
Drawing a line on an inner JPanel
JFrames or...