0

Okay so i am having a little trouble with my JFormattedTextField. I figured out how to work the MaskFormatter somewhat but not great. the formatting is fine, like when I want to restrict a field to only 15 characters that works but when I move the cursor to another field the text disappears. Not sure whats going on there. I can't find anything about it in the API... although I am quite new at using it so I may simply be looking in the wrong areas. here is a snippit of code that contains the JFormattedTextField:

JFormattedTextField nameArea = new JFormattedTextField(createFormatter("AAAAAAAAAAAAAAA"));

	// creates a MaskFormatter and makes sure the formating is correct
	// taken from java.sun.com
	protected MaskFormatter createFormatter(String s) 
	{
		MaskFormatter formatter = null;
		try 
		{
			formatter = new MaskFormatter(s);
		} 
		catch (java.text.ParseException exc) 
		{
			System.err.println("formatter is bad: " + exc.getMessage());
			System.exit(-1);
		}
		return formatter;
	}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by smoore
0

Thanks a lot! Guess I overlooked that when in the API. I'm assuming I want JFormattedTextField.PERSIST to keep the text in the box? Also will that ensure that I can grab the text later if I want to read it? for example if I have a "NAME" field and I hit a button called "SAVE" and I want the action to grab the text from the field and put it into a variable, will that work?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.