up the xhtml panel XHTMLPanel xhtml = new XHTMLPanel(); xhtml.setDocument(new URL("http://myserver.com/page.xhtml"));
JScrollPane scroll = new JScrollPane(xhtml); JFrame frame = new JFrame("Demo"); frame.getContentPane().add(scroll); frame.pack(); frame.setSize(500,600); frame.show(); }
XHTMLPanel renders XHTML and XML which can be loaded as valid {@link Document}instances. You should make sure the document you want to render is well-formed. For XHTML, there is always a default stylesheet available, even if no CSS is attached to the XHTML you are loading. For XML, there is no default stylesheet, so you should have one attached to your XML before trying to render it using the xml-stylesheer processing instruction. XHTMLPanel has methods to load documents from a uri ( {@link #setDocument(String uri)}), from a Document instance ( {@link #setDocument(Document)}) or from an InputStream ( {@link org.xhtmlrenderer.swing.BasicPanel#setDocument(java.io.InputStream,String)}).
XHTMLPanel also lets you make simple changes with simple methods like {@link #setFontScalingFactor(float)}. If you want to make other changes you will need to get the rendering context ( {@link #getSharedContext()}) and call methods on that. Ex:
XHTMLPanel xhtml = new XHTMLPanel(); RenderingContext ctx = xhtml.getRenderingContext(); ctx.setLogging(true); // turn on logging ctx.setValidating(true); // turn on doctype validation ctx.addFont(fnt,"Arial"); // redefine a font ctx.setDomImplementation("com.cooldom.DomImpl");
XHTMLPanel comes with a pre-installed MouseListener which handles :hover events used for rollovers ( @see org.xhtmlrenderer.swing.HoverListener ). XHTMLPanel also comes with a pre-installed LinkListener used to follow links. ( @see org.xhtmlrenderer.swing.LinkListener ) If you want to disable these for some reason you can get the list of mouse listeners and remove them all.
@author Joshua Marinacci (joshy@joshy.net)
@see
The Flying Saucer Home Page
@see RenderingContext