The Artima Developer Community
Sponsored Link

Java Answers Forum
RTF Editor / Writer and LoadRtf object.

1 reply on 1 page. Most recent reply: Mar 8, 2003 3:15 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Genty hhgjv

Posts: 1
Nickname: gentyjp
Registered: Feb, 2003

RTF Editor / Writer and LoadRtf object. Posted: Feb 27, 2003 12:53 AM
Reply to this message Reply

I search for a sample RTF Editor to study RTF editing in Java.
I found one really interesting in legacy forum java answer, at URL

I tried to compile it but it can't find LoadRtf object.

Could someone tell me where can I find it ?

Thanks for your help.


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: RTF Editor / Writer and LoadRtf object. Posted: Mar 8, 2003 3:15 PM
Reply to this message Reply
Try the code at:
or the following:

* March 9, 2003

import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.text.*;
import javax.swing.text.rtf.*;

/** Constructs an RTF editor kit to display the
* contents of an RTF document in a JEditorPane.
* @author: Charles Bell
* @version March 8, 2003
public class RTFViewer extends JFrame{

private RTFEditorKit kit;
private File file;
private JEditorPane editor;

/** Default constructor. */
public RTFViewer(){
super("RTF Viewer");

/** Constructor using file object as input. */
public RTFViewer (File file){
super("RTF Viewer: " + file.getName());
this.file = file;

/** Constructor using filename string object as input. */
public RTFViewer (String fileName){
super("RTF Viewer: " + fileName);
this.file = new File(fileName);

/** Runs as application. */
public static void main(String[] args){
if (args.length == 0){
new RTFViewer();
new RTFViewer(args[0]);

/** Creates a default document to hold the contents of the RTF
* file, and displays its contents in a JEditorPane.
public void init(){
kit = new RTFEditorKit();
editor = new JEditorPane();
Document doc = kit.createDefaultDocument();
if (file == null) {
file = getFile();
if (file == null) {
setTitle("RTF Viewer: " + file.getName());
FileInputStream fis = new FileInputStream(file);,doc,0);
getContentPane().add(new JScrollPane(editor), BorderLayout.CENTER);
}catch (BadLocationException ble){
System.err.println("BadLocationException: " + ble.getMessage());
}catch (IOException ioe){
System.err.println("IOException: " + ioe.getMessage());

/** Uses a JFileDialog to retrieve a file from the user.
private File getFile(){
File f = null;
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new RTFFileNameFilter());
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
f = fileChooser.getSelectedFile();
return f;

/** Control exit. */

private void exit(){

/** For the rtf file filter.
class RTFFileNameFilter extends javax.swing.filechooser.FileFilter{

public boolean accept(File file){
boolean status = false;
String filename = file.getName().toLowerCase();
return (filename.indexOf("rtf") > 0);

public String getDescription(){
return "RTF file";


Flat View: This topic has 1 reply on 1 page
Topic: COOL Java Menu Previous Topic   Next Topic Topic: Word Frequency Data

Sponsored Links


Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use