Ola pessoal tudo bem, espero que sim.
To Aqui tentando desenvolver um JComboBox que aceite somente Maiusculas e com um MaxLenght tambem, eu tenho um exemplo aqui que eu implementei em um JTextField mais to tentando fazer o mesmo no JComboBox e ele nao aceita, tem alguma coisa a ver com o Override, obrigado a todos
Segue a classe JTextField Maiuscula e com MaxLength :
public class JTextLimitado extends JTextField{
@Override
protected Document createDefaultModel() {
return new LimitedCaseDocument();
}
private final class LimitedCaseDocument extends PlainDocument {
@Override
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {
int iMaxLength = getColumns();
if (str == null) {
return;
}
char[] upper = str.toCharArray();
for (int i = 0; i < upper.length; i++) {
upper[i] = Character.toUpperCase(upper[i]);
}
str = new String(upper);
if (iMaxLength <= 0) { // aceitara qualquer no. de caracteres
super.insertString(offs, str, a);
return;
}
int ilen = (getLength() + str.length());
if (ilen <= iMaxLength) { // se o comprimento final for menor...
super.insertString(offs, str, a); // ...aceita str
} else {
if (getLength() == iMaxLength) {
return; // nada a fazer
}
String newStr = str.substring(0, (iMaxLength - getLength()));
super.insertString(offs, newStr, a);
}
}
}
}
Valeu Pessoal um Abraco a Todos.