, EDT?
append EDT, JTextArea .
, , :
import java.awt.TextArea;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class Sample {
public static void main(String[] args) {
showAndFillTextArea("Not on EDT", 0, 0);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
showAndFillTextArea("On EDT", 400, 0);
}
});
}
private static void showAndFillTextArea(String title, int x, int y) {
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea textArea = new JTextArea(20, 20);
JScrollPane scrollPane = new JScrollPane(textArea);
frame.getContentPane().add(scrollPane);
frame.pack();
frame.setLocation(x, y);
frame.setVisible(true);
for(int i = 0; i < 50; i++) {
textArea.append("Line" + i + "\n");
}
}
}
source
share