How can I create an instance of the Java console inside of a GUI panel?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
@Sofware Monkey:
It works! :)
ByteArrayOutputStream can be used to omit buffering stuff.
Rather than limiting line number, you can bind ByteArrayOutputStream#reset() to some button.
I recently use the excellent code provided by Lawrence Dol in one of my project.
However, in my case the code consumed too many memory. I managed to reduce drastically the memory comsuption by replacing
JTextarea
by aJLabel
.My memory saving searches showed that
JTextarea
internal code tends to hold the actual text sent too much time. Consequently, all this text could not be garbage collected.Here is the flexible version of initial code (with thread synchronization replaced by locks).
JComponentOutputStream.java
Sample usage
Here's a functioning class. You can install an instance of this into the system out and err using:
Updated 2014-02-19: To use EventQueue.invokeLater() to avoid GUI threading issues which can crop up very rarely with the original.
Updated 2014-02-27: Better implementation
Updated 2014-03-25: Correct recording & deletion of lines in text area to be within the
run()
method to avoid race-condition between appending and deleting which can happen if the console is flooded with output. The end result seems cleaner to me, as well.And here's a screenshot of it in action:
I know that this is an old thread but the fact that I found it while trying to figure out a good way of doing this means others probably will too.
Here's a (Probably) cleaner way of doing what software monkey posted: