|
-
Input validation in JFormattedTextField
I need to restrict the size as well as check the Input characters entered in the JFormattedTextField.
I know that to restrict the size I can use
t1= new JFormattedTextField(new MaskFormatter("*****"));
For checking the characters entered in the Field, here is the class.
class FilteredFormatter extends DefaultFormatter {
protected DocumentFilter getDocumentFilter() {
return new InputFilter();
}
}
class InputFilter extends DocumentFilter {
String domain = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.";
public void insertString(DocumentFilter.FilterBypass fb,
int offset,
String str,
AttributeSet attr) throws BadLocationException
{
replace(fb, offset, 0, str, attr);
}
public void replace(DocumentFilter.FilterBypass fb,
int offset,
int length,
String str,
AttributeSet attrs) throws BadLocationException {
char[] source = str.toLowerCase().toCharArray();
char[] result = new char[source.length];
int j = 0;
for(int i = 0; i < result.length; i++)
if(domain.indexOf(source[i]) != -1)
result[j++] = source[i];
fb.replace(offset, length, new String(result, 0, j), attrs);
}
}
I can do that by creating the new Instance
t1= new JFormattedTextField(new FilteredFormatter());
I want both size and charvalidation. With this only one is possible at a time. How do I get both with the above code?
Similar Threads
-
By AM003295 in forum VB Classic
Replies: 4
Last Post: 06-16-2005, 12:47 AM
-
By adohelp in forum VB Classic
Replies: 0
Last Post: 12-26-2001, 11:32 AM
-
Replies: 0
Last Post: 10-24-2001, 04:09 PM
-
Replies: 1
Last Post: 09-14-2000, 11:04 AM
-
By N. Richards in forum VB Classic
Replies: 1
Last Post: 09-09-2000, 05:50 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks