This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTextField validation / Document Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField validation / Document Listener" Watch "JTextField validation / Document Listener" New topic
Author

JTextField validation / Document Listener

Pam Ginther
Greenhorn

Joined: Jul 10, 2002
Posts: 10
Good Morning,
I am validating a JTextField on a GUI via a ConstraintException on a set method in a value bean. I am using a DocumentListener on the JTextField to call the set method. When I hit a constraint I want to reset the JTextField to the value in the value bean. I am receiving the error java.lang.IllegalStateException: Attempt to mutate in notification.
try {
gui.getTextField().getDocument().insertString(0, valueBean.getValue(), null);
} catch (BadLocationException e) {}
From what I have read the text field can't deal with a change event while reacting to a user's change, but this seems like the most logical place.
Any thoughts/ideas would be greatly appreciated.
Pam
 
Don't get me started about those stupid light bulbs.
 
subject: JTextField validation / Document Listener
 
It's not a secret anymore!