Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Working on Rich Text Format on Slide Using Java

                         


In this example we are going to create a slide then we will learn how we can work on rich text using java.

In this example we are creating an object of  SlideShow after that we are using createSlide() method to create an object of  Slide. To make a textbox we need first create an object of  TextBox .Then by use of setText(String str) we can pass the string value in textbox.To get blocks of text we need  getTextRuns() 
The getTextAsString()  and getTextAsVector() are two method which is used to get the text back. The getTextAsString()  returns a single string with all the text in it and getTextAsVector()  returns a vector of strings, one for each text record found in the file.
Changing Tex. We can change the text via  TextRun.setText(String) or RichTextRun.setText(String). But it is not yet possible to add additional TextRuns or RichTextRuns
Methods used in this example::

setText(java.lang.String text):
 This method is used to change the text or to set the text.

setBold(boolean bold):
This method is used set text is bold or not.

setItalic(boolean italic):
This method is used to set italic type .

setUnderlined(boolean underlined):
This method is used to set underline.

setFontSize(int fontSize):
This method is used to set the font size.

setFontColor(int bgr):
This method is used to set the background color of the text.

setFontColor(java.awt.Color color):
This method is used to set the color of the text, as a java.awt.Color 

setAlignment(int align):
This method is used to set the type of horizontal alignment for the text.

 The code of the program is given below:
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.usermodel.RichTextRun;
import java.io.*;
import java.awt.*;
import org.apache.poi.hslf.model.TextBox;
class workingWithTextFormat
{
  public static void main(String a[])
  {
  try
  {   SlideShow slideShow = new SlideShow();
       Slide slide = slideShow.createSlide();
    
     TextBox txt = new TextBox();
        txt.setText("Rajesh Kumar!");
        txt.setAnchor(new java.awt.Rectangle
(
30010020050));
        RichTextRun richTextRun = txt.getTextRun().
getRichTextRuns
()[0];
        richTextRun.setFontSize(45);
        richTextRun.setFontName("Arial");
        richTextRun.setBold(true);
        richTextRun.setItalic(true);
        richTextRun.setUnderlined(true);
        richTextRun.setFontColor(Color.red);
        richTextRun.setAlignment(TextBox.AlignRight);
        slide.addShape(txt);
        FileOutputStream out = new FileOutputStream
(
"richTextRun.ppt");
        slideShow.write(out);
        out.close();
  }catch(Exception e){}
  }}

The output of the program is given below:

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

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.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.