java fx的新手。我的问题是,有没有办法让我通过System.out
打印的所有文字进入文本区域?我应该将所有打印件放入一个方法中,还是必须将each one
传递给textarea?
答案 0 :(得分:3)
您可以更改输出流,请遵循以下代码:
TextArea ta = new TextArea();
Scene scene = new Scene(ta);
System.setOut(new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
ta.appendText("" + ((char)b));
}
@Override
public void write(byte[] b) throws IOException {
ta.appendText(new String(b));
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
ta.appendText(new String(b, off, len));
}
}));
stage.setScene(scene);
stage.show();
System.out.println("THIS WILL BE WRITEN INSIDE THE TEXT AREA!");