Share on Google+Share on Google+

changing Chunk Color

In this section, you will see how to change chunk color in java.

changing Chunk Color


In this program we are going to tell you how you can change the color of chunk color .This example tell you how you can change the color of chunk and how you can add fonts and gives the size of the fonts.

Code Description:

In this Example we create the object of the paragraph .In this paragraph we add the chunk and  set the font by using the getFont(fontname,size,coloor ).The getFont() method is a method of FontFactory. We are changing the color of the chunk by passing the color values into the getFont() method.

The class FontFactory is used to create a Font. It is easiest way to get a new Font object. FontFactory has an API with methods that can construct a Font object of any kind. The constructed font is in a uniform way. There are some CID fonts which are not in it.

The getFont() method is used to gets the current font for the window.The getFont method is used to get Font-Object from FontFactory class.

This is used to set the default size.

Color(0xFF, 0x00, 0x00):
This constructor is used to create the object of the color. We pass three hexadecimal values to which gives  the combination of colors. 

This is used to set text BOLD. 

This is used to set text ITALIC.

This is used to set text style HELVETICA.

The code of the program is given below:

import java.awt.Color;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
public class changeChunkColor {
  public static void main(String[] argsthrows Exception
  Document document = new Document();
  PdfWriter writer = PdfWriter.getInstance(document,new 
  Paragraph paragraph;
  paragraph = new Paragraph("Roses");
  paragraph.add(new Chunk("india", FontFactory.getFont
FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD, new 
  paragraph = new Paragraph("India");
  paragraph.add(new Chunk(".net", FontFactory.getFont

The output of the program is given below:

Download this example.




Posted on: April 17, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: changing Chunk Color   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image