File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to set the font type for a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to set the font type for a "string"" Watch "how to set the font type for a "string"" New topic

how to set the font type for a "string"

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
hi there,

Does anyone know how to change the color and font for a String?

I'd like my result to be like:

System.out.println("Due Date:" + record.getDueDate() ");

how can I make the record.getDueDate() with .setFont() ???

Thanks for any help
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
System.out.println prints to a DOS window that is always 2 colors (background and text) and a standard font.
If you were to print using a graphics object on something that could produce Fonts and colors you would do this:

Create a new Font Object with the desired characteristics (see Java API for Font constructors).

Set the font of your graphics object using the setFont method and your newly-created Font object.

Set the color of your graphics object using the setColor method and a static object of the Color class (see classes Graphics and Color in the Java API as needed).

Now print using the graphics object.
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Have a look at the working with text and fonts tutorial
I agree. Here's the link:
subject: how to set the font type for a "string"
It's not a secret anymore!