rzvika
asked on
JEditPane
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.setVisibl e(true);
m_pnlHtmlBrowser.setBackgr ound(Color .red);
getContentPane().add(m_pnl HtmlBrowse r);
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.setEditor Kit(new javax.swing.text.html.HTML EditorKit( ));
System.out.println(m_pnlHt mlBrowser. getContent Type());
m_pnlHtmlBrowser.setText(m _strHtmlCo ntent);
repaint();
validate();
}
//member declaration
JEditorPane m_pnlHtmlBrowser = new JEditorPane();
String m_strHtmlContent = "<HTML><HEAD><TITLE>Critic al Analysis</TITLE></HEAD><BO DY BGCOLOR=\"#00ff40\" TEXT=\"#804000\"><B>BOLD</ B> Normal <I>Italic</I></BODY></HTML >";
}
//------------
//------------
//import com.sun.java.swing.*;
import javax.swing.*;
import java.awt.*;
public class MainWindow extends JWindow
{
MainWindow()
{
super();
addWindowListener(new StdWindowAdapter());
m_pnlHtmlBrowser.setVisibl
m_pnlHtmlBrowser.setBackgr
getContentPane().add(m_pnl
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
m_pnlHtmlBrowser.setEditor
System.out.println(m_pnlHt
m_pnlHtmlBrowser.setText(m
repaint();
validate();
}
//member declaration
JEditorPane m_pnlHtmlBrowser = new JEditorPane();
String m_strHtmlContent = "<HTML><HEAD><TITLE>Critic
}
//------------
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.ht ml.HTMLEdi torKit());
works exactly like
setEditorKit(jEditorPane1. getEditorK itForConte ntType("te xt/html")) ;
at least in Swing 1.0.2
)
hope this helps
heyhey
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.ht
works exactly like
setEditorKit(jEditorPane1.
at least in Swing 1.0.2
)
hope this helps
heyhey
ASKER
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
isn't there a way to do it with this version?
(and what is javax? (is it only in jdk 1.2?))
thank you
javax.swing is the new name of the Swing package (com.sun.java.swing)
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............
ASKER
ASKER
jEditorPane1 = new com.sun.java.swing.JEditor
jEditorPane1.setBounds(0,0
jEditorPane1.setFont(new Font("Serif", Font.PLAIN, 12));
jEditorPane1.setForeground
jEditorPane1.setBackground
jEditorPane1.setEditorKit(
jEditorPane1.setText(getTe
(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!