1. Create controls
Jscrollpane htmlscrollpane = new jscrollpane ();
Jeditorpane htmlpane = new jeditorpane ();
Htmlscrollpane. getviewport (). Add (htmlpane );
Htmlpane. seteditable (false );
2. Apply htmleditorkit to jeditorpane
Htmleditorkit kit = new htmleditorkit ();
Htmlpane. seteditorkit (KIT );
3. Add a style for the style sheet
Stylesheet = kit. getstylesheet ();
Stylesheet. addrule ("table {border-collapse: collapse; Border: solid #000000; border-width: 1px 0 0 1px ;}");
Stylesheet. addrule ("Table caption {font-size: 12px; font-weight: bolder ;}");
Stylesheet. addrule ("Table TD {white-space: Word-wrap; font-size: 10px; Height: 10px; Border: solid #000000; border-width: 0 1px 1px 0; padding: 2px; text-align: Left; Vertical-align: Center }");
4. Add a click event for the link
By default, jeditorpane does not respond to link clicks. You should add a listener.
Htmlpane. addhyperlinklistener (New hyperlinklistener (){
Public void hyperlinkupdate (hyperlinkevent e ){
If (E. geteventtype () = hyperlinkevent. eventtype. Activated ){
// If the link is clicked
// Do something
}
}
};
5. Create a document and apply it to jeditorpane
Document Doc = kit. createdefadocument document ();
Htmlpane. setdocument (DOC );
String html = generatehtml (); // call other methods to generate an HTML string
Htmlpane. settext (HTML );