Question

Pretty new to java fx. My question is, is there a way that all the text I print through System.out to go into a textarea? Should I put all my prints into one method, or do I have to pass each one to the textarea?

Was it helpful?

Solution

you can change the output stream, follow this code:

    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!");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top