hello friends,

I am making a GUI for a certain fill up form using netbeans..here I need disable a "next" button until all the text fields are filled up...I have tried writing a method that which is called during every keypress event in a text box that checks whether the rest of the text boxes are non empty and the status of the text box from which the key press event came from and then enables the button.but this method gets a bit messy since it has to look for too many conditions to get around the problem of user pressing unnecessary keys (such as backspace,space,arrow keys etc...)....is there any other way of solving this problem.

thanks

After a quick look at the API of the JTextField, (which you should always read whenever you have a problem), I found this method:
addInputMethodListener.
It is inherited by the super class: JTextComponent.

I have never used it, but I believe that you should try to add an InputMethodListener to all of your TextFields. If you do that and implement the method: inputMethodTextChanged of the InputMethodListener interface, that method will be called whenever you change the text of your fields. So just take the text entered from the event argument and check the text field has any.

Try to experiment by adding System.out.printlns to your code.

The inputMethodTextChanged takes as argument a InputMethodEvent. Try to make changes to a field that has that listener and then print that event and see if you can find something that you can use

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.