public class XHTMLPanel extends BasicPanel
JScrollPane
. The most common usage is to stuff a URL
into it and then add it to your JFrame. Ex:
import org.xhtmlrenderer.simple.*; ..... public static void main(String[] args) { // set 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 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 (setDocument(String uri)
),
from a Document instance (setDocument(Document)
) or from an InputStream
(BasicPanel.setDocument(java.io.InputStream,String)
).
setFontScalingFactor(float)
. If you want to make other changes you will
need to get the rendering context (BasicPanel.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.
RenderingContext
,
Serialized FormJPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
formSubmissionListener
active_element, doc, documentListeners, enclosingScrollPane, focus_element, hovered_element, sharedContext
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
XHTMLPanel()
Instantiates an XHTMLPanel with no
Document loaded by default. |
XHTMLPanel(UserAgentCallback uac)
Instantiates a panel with a custom
UserAgentCallback
implementation. |
Modifier and Type | Method and Description |
---|---|
void |
decrementFontSize()
Decrements all rendered fonts on the current document by the current
scaling factor for the panel.
|
float |
getMaxFontScale()
Returns the maximum font scaling that may be applied, e.g.
|
float |
getMinFontScale()
Returns the minimum font scaling that may be applied, e.g.
|
void |
incrementFontSize()
Increments all rendered fonts on the current document by the current
scaling factor for the panel.
|
void |
relayout()
Lays out the current document again, and re-renders.
|
void |
resetFontSize()
Resets all rendered fonts on the current document to the font size
specified in the document's styling instructions.
|
void |
setDocument(Document doc)
Renders an XML Document instance.
|
void |
setDocument(Document doc,
String url)
Renders a Document using a URL as a base URL for relative
paths.
|
void |
setDocument(File file)
Renders a Document read from an InputStream using a URL
as a base URL for relative paths.
|
void |
setDocument(InputStream stream,
String url)
Renders a Document read from an InputStream using a URL
as a base URL for relative paths.
|
void |
setDocument(String uri)
Loads and renders a Document given a uri.
|
void |
setFontScalingFactor(float scaling)
Sets the scaling factor used by
incrementFontSize() and
decrementFontSize() --both scale the font up or down by this
scaling factor. |
void |
setMaxFontScale(float f)
Sets the maximum font scaling that may be applied, e.g.
|
void |
setMinFontScale(float f)
Sets the minimum font scaling that may be applied, e.g.
|
void |
setSharedContext(SharedContext ctx)
Sets the
RenderingContext attribute of the XHTMLPanel object. |
addDocumentListener, addMouseTrackingListener, assignPagePrintPositions, doRender, getDocument, getDocumentTitle, getFixedRectangle, getMouseTrackingListeners, getSharedContext, getURL, isActive, isCenteredPagedView, isFocus, isHover, isInteractive, isOpaque, loadDocument, paintComponent, paintPage, printTree, reloadDocument, reloadDocument, removeDocumentListener, removeMouseTrackingListener, resetMouseTracker, scrollTo, setCenteredPagedView, setDocument, setDocument, setDocumentFromString, setDocumentRelative, setFormSubmissionListener, setInteractive, setLayout, setOpaque, setSize, submit
addNotify, doDocumentLayout, doLayout, find, find, fireDocumentLoaded, fireDocumentStarted, fireOnLayoutException, fireOnRenderException, getCellRendererPane, getLayoutContext, getLayoutWidth, getPreferredScrollableViewportSize, getRootBox, getRootLayer, getScreenExtents, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, init, isDefaultFontFromComponent, isExtentsHaveChanged, isNeedRelayout, isPrintView, newLayoutContext, newRenderingContext, removeNotify, repaintRequested, resetScrollPosition, setDefaultFontFromComponent, setDocument, setEnclosingScrollPane, setNeedRelayout, setRootBox, validate
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public XHTMLPanel()
Document
loaded by default.public XHTMLPanel(UserAgentCallback uac)
UserAgentCallback
implementation.uac
- The custom UserAgentCallback implementation.public void relayout()
public void setDocument(String uri)
setDocument
in class BasicPanel
uri
- public void setDocument(Document doc)
doc
- The document to render.public void setDocument(Document doc, String url)
setDocument
in class BasicPanel
doc
- The new document valueurl
- The new document valuepublic void setDocument(InputStream stream, String url) throws Exception
setDocument
in class BasicPanel
stream
- The stream to read the Document from.url
- The URL used to resolve relative path references.Exception
public void setDocument(File file) throws Exception
file
- The file to read the Document from. Relative paths
will be resolved based on the file's parent directory.Exception
public void setSharedContext(SharedContext ctx)
RenderingContext
attribute of the XHTMLPanel object. Generally
you should not use this unless you have a heavily customized context to
use. To modify just some rendering behavior, consider using
BasicPanel.getSharedContext()
to retrieve the current context, and using
mutators to change its behavior.setSharedContext
in class BasicPanel
ctx
- A new RenderingContext to use for rendering.public void setFontScalingFactor(float scaling)
incrementFontSize()
and
decrementFontSize()
--both scale the font up or down by this
scaling factor. The scaling roughly modifies the font size as a multiplier
or divisor. A scaling factor of 1.2 applied against a font size of 10pt
results in a scaled font of 12pt. The default scaling factor is
1.2F.public void incrementFontSize()
setFontScalingFactor(float)
, and reset to the document's specified
font size with resetFontSize()
.public void resetFontSize()
public void decrementFontSize()
setFontScalingFactor(float)
, and reset to the document's specified
font size with resetFontSize()
.public float getMaxFontScale()
public float getMinFontScale()
public void setMaxFontScale(float f)
public void setMinFontScale(float f)
Copyright © 2017. All rights reserved.