Skip to main content



      Home
Home » Newcomers » Newcomers » bind system standard output to Text widget
bind system standard output to Text widget [message #160075] Mon, 10 July 2006 10:22 Go to next message
Eclipse UserFriend
Originally posted by: scamatrallera.gmail.com

hi,
someone can tell me how to bind system standard output to an swt Text
widget in a standalone application?

tank you and have a nice day!

Peter
Re: bind system standard output to Text widget [message #160097 is a reply to message #160075] Mon, 10 July 2006 11:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wayne.beaton.eclipse.org

Peter wrote:
> hi,
> someone can tell me how to bind system standard output to an swt Text
> widget in a standalone application?
>
> tank you and have a nice day!
>
> Peter
>
>

Check out:

http://forum.java.sun.com/thread.jspa?threadID=148084&me ssageID=420078

The gist of it is that you can tell System to redirect System.out to an
alterate PrintStream. You should be able to create your own PrintStream
that does whatever you want, including printing output to an SWT Text
widget.
Re: bind system standard output to Text widget [message #160129 is a reply to message #160097] Mon, 10 July 2006 11:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: scamatrallera.gmail.com

thank you,

the problem is that I've redirected System.out to a new PrintStream but I
don't know how to automatically refresh the text widget each time someone
write to the stream.

I've something like this

thank yuo again!
Re: bind system standard output to Text widget [message #160147 is a reply to message #160129] Mon, 10 July 2006 12:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wayne.beaton.eclipse.org

Peter wrote:
> thank you,
>
> the problem is that I've redirected System.out to a new PrintStream but
> I don't know how to automatically refresh the text widget each time
> someone write to the stream.
>
> I've something like this
>
> thank yuo again!
>
Try something like this:

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

public class ConsumeSysout {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Text text = new Text(shell, SWT.NONE);
shell.open();

OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
text.append(Character.toString((char) b));
}
};
System.setOut(new PrintStream(out));

System.out.println("Hello World!");

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Re: bind system standard output to Text widget [message #160155 is a reply to message #160147] Mon, 10 July 2006 14:03 Go to previous message
Eclipse UserFriend
Originally posted by: scamatrallera.gmail.com

it works fine!!!

thank you very mutch!!!
Previous Topic:Creating Extension Points
Next Topic:Not resolving an import
Goto Forum:
  


Current Time: Wed Jul 23 17:27:43 EDT 2025

Powered by FUDForum. Page generated in 0.07943 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top