I'm working on a form and I'd like to have a drop-down box where you select a person. It brings up their stored information in 开发者_StackOverflow中文版the text-fields below, but as soon as you edit one of the text-fields it disables the drop-down box until you save or cancel the changes. The purpose of this is to prevent the user from editing something, thinking it's saved, and then changing to a different person and losing their changes.
Add a DocumentListener to all your text fields. Whenever any data is changed you disable the combo box. When the data is saved you enable the combo box.
See How to Write a DocumentListener for more information and examples.
A better approach might be to popup a JDialog with the data to be changed.
Dynamically disabling combo boxes doesn't seem like a common practice. Perhaps instead you could indicate to the user when something is saved, and if the user attempts to switch people after info has been inputted, you could notify them and ask if they want to continue and lose the data. Is it not possible that some users will enter data, try to use a disabled combo box, and not knowing why it is disabled, they will think you program is broken?
精彩评论