eu tenho uma função p abrir um arquivo texto. ele faz quebra de linha normalmente, mas eu gostaria q a quebra de linha do arquivo n seja quando o tamanho do JtextArea acabe e sim de acaordo com a formatação do texto original
ou seja pular linha se no texto original a linha pular .
como fazer isso?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Carregar extends JFrame{
JTextArea textArea;
JButton btn;
JButton btc;
public Carregar() {
super("Carregando um arquivo SQL");
Container c = getContentPane();
FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
c.setLayout(layout);
textArea = new JTextArea(10, 40);
textArea.setLineWrap(true);
class SQLfilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".sql");
}
public String getDescription() {
return "arquivos SQL";
}
}
btc = new JButton ("Copiar");
btc.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
textArea.copy();
}
});
btn = new JButton("Abrir Arquivo");
btn.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new SQLfilter());
int res = fc.showOpenDialog(null);
if(res == JFileChooser.APPROVE_OPTION){
File arquivo = fc.getSelectedFile();
textArea.setText("");
try {
BufferedReader in = new BufferedReader(new FileReader(arquivo));
String str, texto = "";
while((str = in.readLine()) != null){
texto += str;
}
textArea.setText(texto);
in.close();
}
catch (IOException ioe){
// possiveis erros são tratatos aqui
}
}
}
});
c.add(textArea);
c.add(btn);
c.add (btc);
setSize(500, 500);
setVisible(true);
}
public static void main(String args[]){
Carregar app = new Carregar();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
ajudem -me
