我在一个要动态更新的类中有一个 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
}
}