Olá Pessoal, preciso que um JTextArea Seja atualizado em tempo real, mas ela só atualiza no final do processamento.
Gostaria que atualizasse a cada linha, mas não ta indo.
Segue exemplo
[code]import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class TesteUpJTextArea implements ActionListener {
private TextResults results;
private JButton start;
public TesteUpJTextArea(){
results = new TextResults(10, 30);
start = new JButton("Start");
start.addActionListener(this);
JPanel panel = new JPanel(new BorderLayout());
panel.add(start, BorderLayout.NORTH);
panel.add(results.getPanel(), BorderLayout.CENTER);
JFrame frame = new JFrame();
frame.setTitle("Teste");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
public static void main(String args[]) {
new TesteUpJTextArea();
}
@Override
public void actionPerformed(ActionEvent event) {
if (event.getSource() == start){
for (int i = 0; i < 10000; i++) {
results.setResult("Linha" + (i + 1));
}
JOptionPane.showMessageDialog(null, "Fim de Atualização");
}
}
}
class TextResults {
private JTextArea out;
private JPanel panel = new JPanel(new BorderLayout());
private String text = "";
private String intervalo = "\n";
private int x;
private int y;
public TextResults(int x, int y) {
this.x = x;
this.y = y;
out = new JTextArea(x, y);
out.setEditable(false);
out.setLineWrap(true);
JScrollPane scroll = new JScrollPane(out);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroll, BorderLayout.CENTER);
}
public void setResult(String addRel){
text += addRel + intervalo;
out.append(addRel + intervalo);
out.select((text.length() -1), (text.length() -1));
}
public JTextArea getOut() {
return out;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public void setIntervalo(String intervalo) {
this.intervalo = intervalo;
}
public String getIntervalo() {
return intervalo;
}
public JPanel getPanel() {
return panel;
}
}[/code]
Desde já, grato