因此,我正在製作的程序使用2個線程:一個用於GUI,一個用於執行工作。添加文本到JTextArea(追加或設置文本)
我想從工作線程/類更新以在GUI類中的JTextArea上打印出來。 我試過的所有東西似乎都不起作用。我添加了行來在控制檯上打印出文本,然後將文本添加到JTextArea中,以確保它已到達行,但每次控制檯都獲得文本但GUI中的JTextArea沒有發生更改。
public static void consoleText(String consoleUpdate){
GUI.console.append(consoleUpdate);
}
我在工作班上試過這個,但沒有發生任何事。 任何人都知道如何解決我的問題?
編輯:
MAIN.JAVA
public class main {
public static void main(String[] args) {
Thread t1 = new Thread(new GUI());
t1.start();
}
GUI.JAVA
public class GUI extends JFrame implements Runnable{
public static JTextArea console;
private final static String newline = "\n";
public void run(){
GUI go = new GUI();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(350, 340);
go.setVisible(true);
}
public GUI(){
setLayout(new FlowLayout());
console = new JTextArea(ConsoleContents, 15, 30);
add(console);
}
WORK.JAVA
...{
consoleText("\nI want this text on the JText Area");
}
public static void consoleText(String consoleUpdate){
GUI.console.append(consoleUpdate);
}
不知道如何任何人都可以幫助你,更快地發佈[SSCCE](http://sscce.org/),簡短,可運行,可編譯,僅關於'JTextArea#append(「String」 )' – mKorbel
歡迎在這個論壇上,請[請參閱常見問題](http://stackoverflow.com/faq) – mKorbel
好吧我會嘗試截斷它足以發佈 – Emm