Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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.

FontFactory:
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.
                     
getFont:

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.

Font.DEFAULTSIZE:
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. 

Font.BOLD:
This is used to set text BOLD. 

Font.ITALIC:
This is used to set text ITALIC.

FontFactory.HELVETICA:
This is used to set text style HELVETICA.

The code of the program is given below:

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
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
              {
    System.out.println("FontColor");
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document,new 
FileOutputStream
("changeChunkColor.pdf"));
    document.open();
          Paragraph paragraph;
      paragraph = new Paragraph("Roses");
      paragraph.add(new Chunk("india", FontFactory.getFont
(
FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD, new 
Color
(0xFF0x000x00))));
      document.add(paragraph);
      paragraph = new Paragraph("India");
      paragraph.add(new Chunk(".net", FontFactory.getFont
(
FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC, new
 
Color(0x000x000xFF))));
      document.add(paragraph);  
    document.close();
  }
}

The output of the program is given below:

Download this example.

 

                         

» View all related tutorials
Related Tags: c web pdf file stl text application import jar diff io make packages port this package itext app if tex

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.