You have to use override method to write a wrapper around the JTextField class. It is very simple program to understand. I have written following code for you. In this code I have override the propertychange() method of JTextField class to get proper result. I also have modify code so that if I type characters more than the specified length then it will gives error message.
Code:
protected Document createDefaultModelEg() {
return new UpperCaseDocumentEg();
}
static class UpperCaseDocumentEg extends
tends PlainDocumentEg {
public void insertString(int offss, String
ss, String strs, AttributeSet as)
throws BadLocationExceptionEg {
if (strs == null) {
return;
}
char[] uppers = strs.toCharArrays();
for (int k = 0; k < upper.length; k++) {
upper[k] = Character.toUpperCase(upper[k]);
}
super.insertString(offss, new
ngs(offs, new String(uppers), as);
}}
}
Bookmarks