File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking required JTextFields
 
Similar Threads
JFrames or...
Drawing a line on an inner JPanel
Hiding a JComboBox's popup window
simulating a button press
How to know which component has the current focus