Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes How to enable a JButton only when certain requirements are fullfilled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to enable a JButton only when certain requirements are fullfilled" Watch "How to enable a JButton only when certain requirements are fullfilled" New topic
Author

How to enable a JButton only when certain requirements are fullfilled

Isuru Buddhika
Greenhorn

Joined: Nov 04, 2012
Posts: 11

I'm designing a GUI for a retail shop system and there I have a form to Add a customer. I want to make the add button enabled only after all the textfields are filled? Can you tell me the best way to do this?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Set the button to "disabled" initially. Each time any of the text fields is changed, check all of them and enable the button if and only if all of the text fields are filled in. And to be notified when any of the text fields is changed, add a DocumentListener to each of them and override the appropriate methods to do that check.
 
jQuery in Action, 2nd edition
 
subject: How to enable a JButton only when certain requirements are fullfilled
 
Similar Threads
J2EE Patterns
Whizlabs SCJA Preparation Kit v 6.0.1: Beware and Enjoy
Google's Operating System ----- Chrome
how to draw on Jwindow?
How come a super class method have a subclass object?