【发布时间】:2013-05-19 01:41:53
【问题描述】:
我想要动态更新的类中有一个 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
}
}
【问题讨论】:
-
你有什么错误吗?
-
如需尽快获得更好的帮助,请发帖SSCCE
-
没有
invokeLater,它可以工作吗? -
我完全删除了 SwingUtilities.invokeLater,只保留了 public void run() 但不,它没有用。除非你想让我从 SwingUtilities 调用不同的方法?
-
很有趣,我不敢相信,同意 SSCCE 的原因是美国东部时间上午缺乏