Capturing System.out.println or stdout data to a swing memo (Huge Data)

て烟熏妆下的殇ゞ 提交于 2019-12-13 00:18:46

问题


Hi I need to show the result in a memo instead using System.out.println, but isn't possible to put the stdout in a list for example and after display the contents of this list in swing memo because I need to display every line of the result in real time or when it is showed.

I'm think in something that works like an observer of System.out.println and when some data or information have been printed in the console I want to be able to capture it and display in a memo.

For a better comprehension, I execute some commands remotely in an unix server and retrieve the results of these commands in the stdout and compute some time and metrics with them, and definitely I need to do in this way to simulate the behavior of an remote application.

The solution could be a way to show every line or every item in the list in the memo in the exactly time that it is produced.

And the swing memo can deal with big strings, more than 500kb or more than 1MB?

Because the entire result printed in the sdtout in my ID is really huge.

Thx


回答1:


See Message Console, for which the description states:

There may be times when you want to capture output from your program and display it for the user. This is generally done by creating a console. Using Swing it is not too difficult to create a simple console using a JTextArea or JTextPane. Our message console will be able to display output written to System.out and System.err. ..

Message Console Screenshot

The JTextPane form of Message Console in append mode.

(Screenshot obtained from the linked article at Rob Camick's 'Java Tips Weblog'.)




回答2:


You can find what you are looking for here :

The webpage is in French, but still code, is quite clear and in java.

Basically, they use to threads to read from 2 PipedOutputStream. One of them is plugged on System.out, the second one is plugged on System.err. When something is available in one of the pipedOutputStream, they write it in the widget.



来源:https://stackoverflow.com/questions/6316272/capturing-system-out-println-or-stdout-data-to-a-swing-memo-huge-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!