The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Issue with JTextField Locking

Hey All!

I'm working on a database access project and have most things working pretty well, with one glaring exception.

I've got a JInternalFrame form with 13 data fields to act as a front-end for a table in my database. Most of these data fields are JTextFields, some two are JRadioButtons, one is a JCheckbox and the last one is a JCombobox.

To prevent accidental data editing, I lock the text fields down by setting JTextField.setEditable(false) and disable the other controls. I have the following method in my form:

If I call this method from a toolbar button ActionPerformed() event and supply `true' as the parameter, it should set the editability of the text fields to true and also enable the other widgets. This seems to work pretty much as expected, except with my txtCity field, for some reason.

When I click on my edit or add toolbar buttons, they call the unlockForm() method with the parameter set to `true'. However, when I attempt to change the data in the txtCity field, it acts as though it is still not editable. So, in an attempt to figure out what is going on here, I placed the following code in the FocusGained() event for the txtCity textbox:

////////////////////////////////////////////////////////////////////////
// DEBUGGING CODE: Remove before release build!
////////////////////////////////////////////////////////////////////////
// The following MessageBox is being displayed because I can not find
// the reason for the city field to not unlock and, yet, it will not
// unlock for editing. I need to figure this out!
////////////////////////////////////////////////////////////////////////
MessageBox mb = new MessageBox();
String msg = "The following are the settings of the city text field:";
msg += "\n-----------------------------------------------------\n";
msg += "txtCity.getName() = " + this.txtCity.getName();
msg += "txtCity.getText() = " + this.txtCity.getText();
msg += "txtCity.isEditable() = " + this.txtCity.isEditable();
msg += "txtCity.isEnabled() = " + this.txtCity.isEnabled();
mb.codeRequired(msg, this);
////////////////////////////////////////////////////////////////////////

Now, when I click on the txtCity text field, I get this message box as expected, with one glaring problem. I get it more than once. Then, when I click on another control, I somehow go into an infinite loop of this message box being displayed and cannot get out of it.

Does anyone have any ideas as to what is going on? Maybe you could point me to a web site or book that actually has this problem and shows how to resolve it. I am at a complete loss as to what's happening, especially since I don't have any code in my FocusLost() event that points to my FocusGained() event. Any help that you can provide will be greatly appreciated.

If it would help to see what the form looks like, you can view it here: