我有一個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