Comme le titre dit, je veux ajouter à mots d'exécution à l'intérieur JTextArea, je simplement écrit ceci:Ajouter des mots au hasard à l'intérieur de l'exécution JTextArea sans l'aide du clavier
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame {
private static final long serialVersionUID = 1L;
private JTextArea tarea;
public Test() {
tarea = new JTextArea(10, 10);
}
private void init() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
insertRandomLetterInsideJtextArea();
JScrollPane scroll = new JScrollPane(tarea);
getContentPane().add(scroll, BorderLayout.CENTER);
pack();
setLocationByPlatform(true);
setVisible(true);
}
private void insertRandomLetterInsideJtextArea() {
while (true) {
tarea.setText("foo\n");
}
}
public static void main(String... args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Test().init();
}
});
}
}
mais il ne fonctionne pas. Le while(true)
ne permet pas de montrer quoi que ce soit. Quelqu'un peut m'expliquer pourquoi?