Deletar linhas no JTextArea

1 resposta
J

Oi pessoal

Como faço pra deletar uma linha em branco no JTextArea?

Obrigado

1 Resposta

J

Aow Galera

Já consegui resolver o problema. Eu indicaria a construção de uma classe derivada do JTextArea mas fiz desse jeito pq eu tinha urgência e estou usando o NetBeans que já declara o JTextArea pra mim.

public String getLine(JTextArea jta, int linha) throws BadLocationException{
        
        int inicio = jta.getLineStartOffset(linha);
        int fim = txaWebDoc.getLineEndOffset(linha);
        return jta.getText(inicio,fim-inicio);
    }

public String filterString(String s, String filter){
        String result = "";
        String ch = "";
        for(int i = 0; i < s.length(); i++){
            ch = s.substring(i,i+1);
            if(!ch.equalsIgnoreCase(filter)) result = result + ch; 
        }
        return result;
    }

public void FiltrarTexto(){
        int count = txaWebDoc.getLineCount();
        String texto = "";
        for(int i = 0; i < count; i++){
            try{
                String linha = getLine(txaWebDoc,i);
                if (linha.equalsIgnoreCase("\n"))
                    linha = filterString(linha,"\n");
                texto = texto + linha;
            }catch(BadLocationException ble){}
        }
        txaWebDoc.setText(texto);    
    }

Falow

Criado 13 de abril de 2007
Ultima resposta 16 de abr. de 2007
Respostas 1
Participantes 1