Get all System.out.println() to redect to JLabel
I have already made a program that is command-line, I just want to convert it to a very basic GUI using a single JLabel and JTextField (so that it will still have pretty much the same interface as command-line).
I haven't done any work on swing yet but have just tried learning some swing using online tutorials and think i have gained some of the basic concepts.
Can I have a JLabel whos parameters are System.out.println's output?
i.e. instead of what would otherwise print to the command line, it would print to the JLabel?
Sorry if what I put makes no sense or if I should be doing something completely different, I am new to swing.
TL;DR
How can I get System.out.println() to direct to a JLabel or what command can I use instead of System.out.println() to print to a JLabel multiple times?
Re: Get all System.out.println() to redect to JLabel
Quote:
Can I have a JLabel whos parameters are System.out.println's output?
i.e. instead of what would otherwise print to the command line, it would print to the JLabel?
Yes, although a JTextArea might be better for multi-line prints. System.out is a PrintStream, you can set this to your own PrintStream instance (see the API for System class) based upon an OutputStream that directs the data to wherever you want, in this case it can direct it to your JTextArea.
Re: Get all System.out.println() to redect to JLabel
Yes,u can.....
direct the data in to setText() method of your component....
and use validate() method to update your screen....
thats it....
hope its useful :)
Re: Get all System.out.println() to redect to JLabel
Quote:
Originally Posted by
rougeking
Yes,u can.....
direct the data in to setText() method of your component....
and use validate() method to update your screen....
thats it....
hope its useful :)
Sorry but this answer is completely and hopelessly wrong. He's talking about *redirecting* the standard output, and doWhile explains how this can be done. setText(...) will do nothing of the kind, and validate() or revalidate() are never necessary for showing text changes in a JLabel.
Re: Get all System.out.println() to redect to JLabel
Quote:
Originally Posted by
Fubarable
Sorry but this answer is completely and hopelessly wrong. He's talking about *redirecting* the standard output, and doWhile explains how this can be done. setText(...) will do nothing of the kind, and validate() or revalidate() are never necessary for showing text changes in a JLabel.
I was getting a little confused by his response, thanks.
So what is it I need to do? If it is actually possible?
Re: Get all System.out.println() to redect to JLabel
Quote:
Originally Posted by
kkid
So what is it I need to do? If it is actually possible?
Did you attempt what I suggested in post #2? If so, what happened? At what step are you confused? If not, give it a try (to add to my previous post, you might need to implement OutputStream, which then appends to an internal buffer when write is called and appends to your UI component when flush is called).
Re: Get all System.out.println() to redect to JLabel
Quote:
Originally Posted by
doWhile
Did you attempt what I suggested in post #2? If so, what happened? At what step are you confused? If not, give it a try (to add to my previous post, you might need to implement OutputStream, which then appends to an internal buffer when write is called and appends to your UI component when flush is called).
OMG, I didn't even see your post, sorry!
I did wonder why Fubarable mention doWhile as I though he was talking about do-while loops lol :P
Ill do your suggestions now, I'm embarrassed now :(blush):