Permitir acentos e caracteres especiais em jtextfield

1 resposta Resolvido
G

Pessoal, boa noite!
Em alguns jtextField do meu sistema, o usuário deverá digitar somente letras maiúsculas. Fiz este método:

public class TeclasPermitidas extends PlainDocument {

<a class="mention" href="/u/override">@Override</a>

public void insertString(int offset, String str, javax.swing.text.AttributeSet attr) throws BadLocationException{

super.insertString(offset, str.toUpperCase().replaceAll("[^a-z|^A-Z|^ ]",""), attr);

}

public void replace(int offset, String str, javax.swing.text.AttributeSet attr) throws BadLocationException{

super.insertString(offset, str.toUpperCase().replaceAll("[^a-z|^A-Z|^ ]",""), attr);

}

}

E aqui informo quais jtextField deverá ser dessa forma:

jTextFieldNome.setDocument(new TeclasPermitidas());

jTextFieldEndereco.setDocument(new TeclasPermitidas());

Até aqui tudo ok. O problema é que nesses campos não está aceitando os acentos e caracter especial, como: Ç.
Como faço para que seja aceito?

1 Resposta

G
Solucao aceita

Consegui resolver, bastava inserir os caracteres que gostaria de permitir assimi:

public class TeclasPermitidas extends PlainDocument {

<a class="mention" href="/u/override">@Override</a>

public void insertString(int offset, String str, javax.swing.text.AttributeSet attr) throws BadLocationException{

super.insertString(offset, str.toUpperCase().replaceAll("[^a-z|^A-Z|Â|Ã|Ê|Ô|Õ|~|ç|Ç|Á|À|É^ ]",""), attr);

}

public void replace(int offset, String str, javax.swing.text.AttributeSet attr) throws BadLocationException{

super.insertString(offset, str.toUpperCase().replaceAll("[^a-z|^A-Z|Â|Ã|Ê|Ô|Õ|~|ç|Ç|Á|À|É^ ]",""), attr);

}

}
Criado 2 de fevereiro de 2017
Ultima resposta 2 de fev. de 2017
Respostas 1
Participantes 1