我有一个JTextArea里面我想动态更新的类。目前它只显示所有处理完成后我附加的文本。我曾试图执行以下操作,解决它:JTextArea不动态更新
public NewConsole(){
initComponents();
}
public void write(final String s){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
textarea.append(s);
}
});
}
控制台获取一个父类实例化:
protected NewConsole console = new NewConsole();
,并输出到它,所有的孩子们叫:
console.write("Append this..");
编辑:这里有一些更多的信息:
public abstract class Parent{
protected NewConsole console = new NewConsole();
public Parent(){}
protected abstract int doSomething();
}
public class Child extends Parent{
public Child(){
console.write("I want this to update dynamically");
doSomething();
console.write("And this..");
}
public int doSomething(){
//Quite intensive processing here
}
}
你有什么错误吗? – acdcjunior
为了更好地为您提供帮助,请发布[SSCCE](http://sscce.org/) – Reimeus
如果没有'invokeLater',它是否有效? – acdcjunior