Skip to Main Content

Java HotSpot Virtual Machine

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!

getting cout output from Java Application

843829Apr 29 2009 — edited May 1 2009
Hello,

My Java application runs native code written in c++.
I need to display some messages from c++ std:cout into a JTextPane.

First, I tried to display the standard PrintStream output "System.out" but it only shows Java messages. Here is my code:
import java.awt.Color;
import java.io.OutputStream;
import java.io.PrintStream;

import javax.swing.JTextPane;

public class LogTextPane extends JTextPane {
	private static final long serialVersionUID = 1L;
	private MyPrintStream mps;
	protected LogTextPane(){
		super();
		this.setBackground(new Color(1,1,0.8f));
		mps = new MyPrintStream(System.out);
		System.setOut(mps);
	}
	class MyPrintStream extends PrintStream {
	    MyPrintStream(OutputStream out){
	    	super(out);
	    }
	
	    public void println(String string){
	        setText(getText() + string + "\n");
	    }
	    
	    public void print(String string) {
	        setText(getText() + string);
	    }
	}	
}
Anyone has an idea? Thanks in advance
Best
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 29 2009
Added on Apr 29 2009
9 comments
509 views