printing in bold and colors

  • Follow


Hi,

How would I print out the following in bold and in red.
System.out.printf("Sum of Parts " + "\n");

How would I do it.

TIA

Roy


0
Reply royng (13) 6/21/2007 3:44:52 PM

On Thu, 21 Jun 2007 11:44:52 -0400, Roy Gourgi wrote:

> Hi,
> 
> How would I print out the following in bold and in red.
> System.out.printf("Sum of Parts " + "\n");
> 
> How would I do it.
> 
> TIA
> 
> Roy

Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm, 
etc.):

System.out.println("\x1B[1mBOLD\x1B[0m\t\x1B[31mRED\x1B[0m");

will print BOLD in bold and RED in red. For more information about 
controlling terminal output, see http://en.wikipedia.org/wiki/
ANSI_escape_code.
0
Reply Joshua 6/21/2007 3:55:52 PM


Thanks Joshua,

There is no easier way than that?
It looks pretty cluttered. :)

I am using JBuilder

Roy

"Roy Gourgi" <royng@videotron.ca> wrote in message 
news:02xei.88$we4.8410@wagner.videotron.net...
> Hi,
>
> How would I print out the following in bold and in red.
> System.out.printf("Sum of Parts " + "\n");
>
> How would I do it.
>
> TIA
>
> Roy
>
> 


0
Reply Roy 6/21/2007 4:03:48 PM

Roy Gourgi wrote:
>> 
>> How would I print out the following in bold and in red. 
>> System.out.printf("Sum of Parts " + "\n");

GIYF
http://www.javaworld.com/javaworld/javaqa/2002-12/02-qa-1220-console.html


>> 
>> How would I do it.
>> 

GIYF
http://www.javaworld.com/javaworld/javaqa/2002-12/02-qa-1220-console.html
0
Reply Ian 6/21/2007 4:21:13 PM

Roy Gourgi wrote:
> There is no easier way than that?
> It looks pretty cluttered.  

Such is the nature of ANSI escape sequences.  You think that's cluttered? 
Take a look at printer control streams sometime.

Bear in mind that by hard-coding ANSI escape sequences you are limiting your 
program to run on consoles that support those escape sewquences, which cuts 
you down to what I would guess to be 90% or more of the consoles you'd 
encounter.  Regardless of the actual proportion it's less than 100%, so you'll 
be sacrificing the "Write Once, Run Anywhere" philosophy of Java.  That might 
be acceptable if you know you can assure ANSI compatibility on all targeted 
consoles.

If you can think up an easier way let us know.  Just remember that these 
escape sequences are defined externally to Java; they're data, not code.

-- 
Lew
0
Reply Lew 6/21/2007 4:33:17 PM

Hi Joshua,

I get the error message that x1B is an illegal escape character?

How can I fix that?

Roy

"Joshua Cranmer" <Pidgeot18@verizon.net> wrote in message 
news:ccxei.2959$AR5.330@trnddc06...
> On Thu, 21 Jun 2007 11:44:52 -0400, Roy Gourgi wrote:
>
>> Hi,
>>
>> How would I print out the following in bold and in red.
>> System.out.printf("Sum of Parts " + "\n");
>>
>> How would I do it.
>>
>> TIA
>>
>> Roy
>
> Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm,
> etc.):
>
> System.out.println("\x1B[1mBOLD\x1B[0m\t\x1B[31mRED\x1B[0m");
>
> will print BOLD in bold and RED in red. For more information about
> controlling terminal output, see http://en.wikipedia.org/wiki/
> ANSI_escape_code. 


0
Reply Roy 6/21/2007 4:51:29 PM

Roy Gourgi wrote:
[reordered top-down]
> "Joshua Cranmer" <Pidgeot18@verizon.net> wrote in message 
> news:ccxei.2959$AR5.330@trnddc06...
>>Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm,
>>etc.):
>>
>>System.out.println("\x1B[1mBOLD\x1B[0m\t\x1B[31mRED\x1B[0m");
>>
>>will print BOLD in bold and RED in red. For more information about
>>controlling terminal output, see http://en.wikipedia.org/wiki/
>>ANSI_escape_code. 
> Hi Joshua,
> 
> I get the error message that x1B is an illegal escape character?
> 
> How can I fix that?
> 
> Roy
Write \u001B instead \x1B

-- 
Thomas
0
Reply Thomas 6/21/2007 5:02:19 PM

Hi Thomas,

That did not work either.

Here is what I entered:

System.out.println("\u001B[1mBOLD\u001B[0m\t\u001B[31mRED\u001B[0m");

And here is the output that I got
BOLD RED

Roy

"Thomas Fritsch" <i.dont.like.spam@invalid.com> wrote in message 
news:newscache$vnwzjj$8w6$1@news.ops.de...
> Roy Gourgi wrote:
> [reordered top-down]
>> "Joshua Cranmer" <Pidgeot18@verizon.net> wrote in message 
>> news:ccxei.2959$AR5.330@trnddc06...
>>>Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm,
>>>etc.):
>>>
>>>System.out.println("\x1B[1mBOLD\x1B[0m\t\x1B[31mRED\x1B[0m");
>>>
>>>will print BOLD in bold and RED in red. For more information about
>>>controlling terminal output, see http://en.wikipedia.org/wiki/
>>>ANSI_escape_code.
>> Hi Joshua,
>>
>> I get the error message that x1B is an illegal escape character?
>>
>> How can I fix that?
>>
>> Roy
> Write \u001B instead \x1B
>
> -- 
> Thomas 


0
Reply Roy 6/21/2007 5:14:25 PM

Roy Gourgi wrote:
> That did not work either.
> 
> Here is what I entered:
> 
> System.out.println("\u001B[1mBOLD\u001B[0m\t\u001B[31mRED\u001B[0m");
> 
> And here is the output that I got
> BOLD RED

Please do not top post.

Does your console use ANSI escape sequences?

-- 
Lew
0
Reply Lew 6/21/2007 5:21:29 PM

I do not know, I am using JBuilder.

How can I find out?

Roy

"Roy Gourgi" <royng@videotron.ca> wrote in message 
news:02xei.88$we4.8410@wagner.videotron.net...
> Hi,
>
> How would I print out the following in bold and in red.
> System.out.printf("Sum of Parts " + "\n");
>
> How would I do it.
>
> TIA
>
> Roy
>
> 


0
Reply Roy 6/21/2007 5:24:57 PM

> I do not know, I am using JBuilder.

Ansi control code works only on Win9x.

http://www.rgagnon.com/javadetails/java-0047.html

On more recent Windows relaease (NT, 2000, XP), you need to use a JNI 
routine.

http://www.rgagnon.com/javadetails/java-0469.html

Bye.
-- 
Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
0
Reply Real 6/22/2007 2:59:34 AM

Real Gagnon wrote:
>> I do not know, I am using JBuilder.
> 
> Ansi control code works only on Win9x.

Huh.  Works fine on my Linux console.  Works fine in my Cygwin console in Win 
XP also.

> http://www.rgagnon.com/javadetails/java-0047.html
> 
> On more recent Windows relaease (NT, 2000, XP), you need to use a JNI 
> routine.
> 
> http://www.rgagnon.com/javadetails/java-0469.html

Or run the program in an ANSI console.  Works fine for me on Win XP.

-- 
Lew
0
Reply Lew 6/22/2007 3:19:14 AM

Lew <lew@lewscanon.nospam> wrote in
news:__GdnaMWN9QvoubbnZ2dnUVZ_oLinZ2d@comcast.com: 

> Real Gagnon wrote:
>>> I do not know, I am using JBuilder.
>> 
>> Ansi control code works only on Win9x.
> 
> Huh.  Works fine on my Linux console.  Works fine in my Cygwin console
> in Win XP also.

My comments were for regular CMD.EXE or COMMAND.COM DOS shell. 

Bye.
-- 
Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
0
Reply Real 6/22/2007 3:56:35 AM

On Thu, 21 Jun 2007 11:44:52 -0400, "Roy Gourgi" <royng@videotron.ca>
wrote, quoted or indirectly quoted someone who said :

>How would I print out the following in bold and in red.
>System.out.printf("Sum of Parts " + "\n");

You can't do it with System.out.  You write the code that would
display it on screen, then feed it to a printer rendering engine. See
http://mindprod.com/jgloss/printing.html

Another way is to generate HTML, then feed it too a browser to print.

another way is to generate some sort of metafile then feed it to a C++
utility to print.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 6/22/2007 6:05:04 AM

Real Gagnon wrote:
> Lew <lew@lewscanon.nospam> wrote in
> news:__GdnaMWN9QvoubbnZ2dnUVZ_oLinZ2d@comcast.com: 
> 
>> Real Gagnon wrote:
>>>> I do not know, I am using JBuilder.
>>> Ansi control code works only on Win9x.
>> Huh.  Works fine on my Linux console.  Works fine in my Cygwin console
>> in Win XP also.
> 
> My comments were for regular CMD.EXE or COMMAND.COM DOS shell. 

The person who suggested ANSI control codes in the first place was careful to 
exclude those.

Joshua Cranmer said:
> Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm, 
> etc.):

So that point was already covered.  Plus, I asked,

> Does your console use ANSI escape sequences?

Interestingly there was no answer to that question.  I also pointed out

> Bear in mind that by hard-coding ANSI escape sequences you are limiting your program to run on consoles that support those escape sewquences,

It is helpful to the OP to know that the command shells you mentioned do not 
fit into the target space for the advice.  The issue that the suggestion is 
not portable was well covered, however.

-- 
Lew
0
Reply Lew 6/22/2007 11:36:51 AM

On Fri, 22 Jun 2007 06:05:04 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>>How would I print out the following in bold and in red.
>>System.out.printf("Sum of Parts " + "\n");
>
>You can't do it with System.out.  You write the code that would
>display it on screen, then feed it to a printer rendering engine. See
>http://mindprod.com/jgloss/printing.html
>
>Another way is to generate HTML, then feed it too a browser to print.
>
>another way is to generate some sort of metafile then feed it to a C++
>utility to print.

Another way is to generate PostScript and then feed that to a PS
printer or software PS rendering engine.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 6/23/2007 11:04:41 AM

15 Replies
359 Views

(page loaded in 0.009 seconds)

Similiar Articles:


















7/24/2012 1:11:40 PM


Reply: