Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HTML text not display correctly on JEditorPane

843806Apr 10 2008 — edited Apr 16 2008
Hi all,

I've use a JEditorPane to display some HTML text and get the URL including in that text. Everything working fine. Here is my code.
private JEditorPane editor = new JEditorPane();

    public void defineEditorPane(String htmlCode){
        
        editor.setEditorKit(new HTMLEditorKit());
        editor.setContentType("text/html");
        editor.setText(null); // Try to clear the initial text
        editor.setSize(jPanel1.getWidth(), jPanel1.getHeight());
        editor.setBorder(new BevelBorder(BevelBorder.LOWERED));
        editor.setEditable(false);
        editor.setText(htmlCode);
        //editor.setBackground(Color.LIGHT_GRAY);
        editor.addHyperlinkListener(this);
        
        jPanel1.add(editor);
        this.setVisible(true);
        setWindowLocation();
    }
I'll explain little more what I have done here.

First create a JDialog and top of that I add a JPanel. Then on the JPanel I add the JEditorPane. I used NetBeans and I do the above way, because I can' t find the JEdiotPane in the Swing Containers Pallet.

My question is this. If I call the above method with a html code, it displayed the content nicely. Then I call the function with a html code, it doesn't display correctly. I can't see them. If I drag the mouse(or select) on the dialog I can see the content.

I think it's clear what I said. So why it is happened. Any bad coding in my method.

Thanks a lot for commenting.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2008
Added on Apr 10 2008
2 comments
169 views