Solved

JEditPane

Posted on 1998-12-10
9
207 Views
Last Modified: 2012-05-04
i want to show text by jEditPane.
as i have understood, i can give the constructor an url or string represents it.
is there a way to give it a string that contains exactly the same text as in the source file of the url?
0
Comment
Question by:rzvika
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Accepted Solution

by:
Hans_Klose earned 50 total points
ID: 1229196
By default you will use DefaultEditorKit which is text/plain is you want tp use setText() with html you must first use
void setEditorKit(EditorKit kit) to get the right editor  
There are several ways to load content into this component.

The setText() method can be used to initialize the component from a string. In this case the current EditorKit will be used, and the content type will be expected to be of this type.

The read method can be used to initialize the component from a Reader. Note that if the content type is html, relative references (e.g. for things like images) can't be resolved unless the <base> tag is used or the Base property on HTMLDocument is set. In this case the current EditorKit will be used, and the content type will be expected to be of this type.

The setPage() method can be used to initialize the component from a URL. In this case, the content type will be determined from the URL, and the registered EditorKit for that content type will be set.

0
 

Author Comment

by:rzvika
ID: 1229197
well i did:

jEditorPane1 = new com.sun.java.swing.JEditorPane();
jEditorPane1.setBounds(0,0,324,444);
jEditorPane1.setFont(new Font("Serif", Font.PLAIN, 12));
jEditorPane1.setForeground(new Color(0));
jEditorPane1.setBackground(new Color(16777215));
jEditorPane1.setEditorKit(jEditorPane1.getEditorKitForContentType("text/html"));
jEditorPane1.setText(getTextPane());

(getTextPane() returns a string).
i created a page of an html and saw what was the code and i told getTextPane() to return this code by string.
in the program, the editor show it as a regular text.
please tell me what's wrong.
thank you!
0
 
LVL 1

Expert Comment

by:Hans_Klose
ID: 1229198
I have had the same problem that you, run into. I thought that this would work. I will take another look at it. And tell you if I figue it out. For now you can try useing the JEditorPane(String type, String text) ; constractor. see if that works better for you. And just put new panel each time you update the Html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Hans_Klose
ID: 1229199
I have done this with 1.2 and it seem to work give it a shoot.
//------------
//import com.sun.java.swing.*;
import javax.swing.*;
import java.awt.*;


public class MainWindow extends JWindow
{
    MainWindow()
    {
        super();
       
        addWindowListener(new StdWindowAdapter());
       
        m_pnlHtmlBrowser.setVisible(true);
        m_pnlHtmlBrowser.setBackground(Color.red);
       
        getContentPane().add(m_pnlHtmlBrowser);
       
        Toolkit oToolKit = getToolkit();
        Dimension oDimenation  = oToolKit.getScreenSize();
       
       
        //make the screen half size of the display and show in the middle
        int x = oDimenation.width/4;
        int y = oDimenation.height/4;
        setBounds(x, y, x*   2, y*2);
        m_pnlHtmlBrowser.setBounds(x, y, x*   2, y*2);
       
        m_pnlHtmlBrowser.setEditorKit(new javax.swing.text.html.HTMLEditorKit());
        System.out.println(m_pnlHtmlBrowser.getContentType());
        m_pnlHtmlBrowser.setText(m_strHtmlContent);
       
       
        repaint();
        validate();
       
    }
   
    //member declaration
    JEditorPane m_pnlHtmlBrowser = new JEditorPane();
   
    String m_strHtmlContent = "<HTML><HEAD><TITLE>Critical Analysis</TITLE></HEAD><BODY BGCOLOR=\"#00ff40\" TEXT=\"#804000\"><B>BOLD</B>   Normal  <I>Italic</I></BODY></HTML>";
   
}
//------------
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229200
it seems that setText does not work with older versions of Swnig (tested with 1.0.2)
you can check this URL for a workaround ...
http://developer.java.sun.com/developer/bugParade/bugs/4132791.html

(note:
setEditorKit(new com.sun.java.swing.text.html.HTMLEditorKit());
works exactly like
setEditorKit(jEditorPane1.getEditorKitForContentType("text/html"));
at least in  Swing 1.0.2
)

hope this helps
  heyhey
0
 

Author Comment

by:rzvika
ID: 1229201
Hans_Klose, your code doesn't work on jdk 1.1.6 (i know you didn't say so), it does the same.
isn't there a way to do it with this version?
(and what is javax? (is it only in jdk 1.2?))
thank you
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229202
javax.swing is the new name of the Swing package (com.sun.java.swing)

0
 
LVL 1

Expert Comment

by:Hans_Klose
ID: 1229203
If you want to make it work with 1.1.6 take heyhey_ s work around it seems to be the only way I have seen so far............

0
 

Author Comment

by:rzvika
ID: 1229204
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question