Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Keep PrintStream Redirect across multiple scenes

2892705Feb 26 2015 — edited Mar 2 2015

Hello to everybody. I have a problem and i could really use some help...

I have a JavaFX application with multiple scenes.

In this applications one scene plays the role of "master" role and the others are loaded according to actions on the "master" scene(buttons,menu items)

The issue is that i need to redirect all the PrintStream activity to a specific TextArea on the "master" scene...

so everything that normally goes to the console to get redirected to that specific TextArea

and this should be global,on every scene that is outputting something it should displayed on the specific TextArea on the "master" scene

The code i am using right now on the "master" scene is :

             Node node =primaryStage.getScene().lookup("#ShowInfo");

            TextArea ta =(TextArea)node;

            FXConsole console = FXConsole.getInstance(ta);

            PrintStream ps = new PrintStream(console, true);

            System.setOut(ps);

            System.setErr(ps);

            System.out.println("Test");

For the rest of the scenes i am using the Singleton Pattern to keep the pointing to the Specific TextArea

       FXConsole console = FXConsole.getInstance(null);

        PrintStream ps = new PrintStream(console, true);

        System.setOut(ps);

        System.setErr(ps);

        System.out.print("Hello There");

        ps.close();

The issue is that i don't like this implementation so ...is there a better solution

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 30 2015
Added on Feb 26 2015
5 comments
7,705 views