- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
JEditorPane
in a JScrollPane
and
provides a set of buttons for navigation. Links that appear in the
HTML may be clicked to visit a URL. The buttons provide the
following functions.
- The "start" button takes you to the URL provided by the
setPage
method. It is equivalent to the maximum possible number of repetitions of the "back" button. - The "back" button returns to the page that was last visited by clicking on a link.
- The "forw" button moves forward, undoing the effects of pushing the "back" button.
- The "end" button is equivalent to the repeated use of the "forw" button.
- The "reload" button reloads the link currently visited.
- the DOWN-ARROW key, plus C-N , moves the view down by roughly one line.
- the UP-ARROW key, plus C-P, moves the view up by roughly one line.
- the PAGE-DOWN key moves the view down by one page, where a page is the size of the window.
- the PAGE-UP key moves the view up by one page, where a page is the size of the window.
- the HOME key, plus M-<, moves the view to the start of the document.
- the END key, plus M-<, moves the view to the end of the document.
Note: The buttons contain icons instead of text, but have text-based tooltips. The icons are in resources named org/bzdev/swing/icons/fleft.gif, org/bzdev/swing/icons/left.gif, org/bzdev/swing/icons/redo.gif, org/bzdev/swing/icons/right.gif, org/bzdev/swing/icons/fright.gif, and org/bzdev/swing/icons/rlredo.gif. These are supplemented for 'reverse video' by icons in the filesorg/bzdev/swing/icons/fleftRV.gif, org/bzdev/swing/icons/leftRV.gif, org/bzdev/swing/icons/redoRV.gif, org/bzdev/swing/icons/rightRV.gif,org/bzdev/swing/icons/frightRV.gif, and org/bzdev/swing/icons/rlredoRV.gif for enabled icons. The disabled icons for reverse video are in resources named org/bzdev/swing/icons/fleftRVD.gif org/bzdev/swing/icons/leftRVD.gif, org/bzdev/swing/icons/redoRVD.gif, org/bzdev/swing/icons/rightRVD.gif, org/bzdev/swing/icons/frightRVD.gif, and org/bzdev/swing/icons/rlredoRVD.gif.
The MIME types supported are those that a JEditorPane
supports.
Internationalization is handled by the resource
org/bzdev/swing/HtmlPaneBundle.properties
. This defines
the strings startText, backText, reloadText, frwdText, endText. as
values to use in buttons if icons are not provided. The strings
startTip, backTip, reloadTip, frwdTip, and endTip provide corresponding
tool tips. Finally, the string direction indicates if the components
should be laid out LR (left to right) or RL (right to left.) This
also has an effect on the how icons are assigned to buttons. The
icon rlredo.gif is the mirror image of redo.gif and is provided for
right-to-left layouts.
One can set the HTML page displayed by calling one of the setPage methods or by using a constructor that takes a URL or a String specifying a URL as an argument.
This component allows HTML pages to be displayed but does not allow them to be edited.
A few methods allow one to set colors to implement a "dark mode" for viewing HTML pages in reverse video. This does change an HTML page's appearance: to change it (e.g., to make the text white and the background dark), a style sheet can be used.
The behavior specified for JEditorPane in Java 11 is such that the
constuctor HtmlPane()
configure a JEditorPane so
that JEditorPane.getPage()
will return null even if
setPage(URL)
or setPage(String)
was
called. This may affect address resolution. The method
getPage()
always returns the page that was last set.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The string that will be displayed as a frame title when a dialog box reporting an error is displayed.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the border for this component's contents.final String
Get the title used in error message dialog boxes.getPage()
get the URL for the page being displayed.boolean
Determine if this HtmlPane is editable.void
setBackground
(Color color) Set the background color.void
setButtonBackground
(Color color, boolean rvmode) Set the background color for the 'start', 'back', 'reload', 'forward', and 'end' controls.void
Set the color of the caret.void
void
setContentLocale
(Locale locale) Set the local of the content pane.void
setContentPaneBorder
(Border border) Set the border for this component's contents.void
setEditable
(boolean value) Set whether or not this HtmlPane is editable.final void
setErrorTitle
(String title) Set the title to use in error message dialog boxes.void
void
Set the page to display and display it.void
Set the page to display and display it.void
setScrollbarBackground
(Color color) Set the background color for scroll bars.Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, 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, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
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, getAccessibleContext, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
errorTitle
The string that will be displayed as a frame title when a dialog box reporting an error is displayed. The default is obtained from the resource bundle org.bzdev.swing.lpack.HtmlPaneBundle
-
-
Constructor Details
-
HtmlPane
public HtmlPane()Constructor. -
HtmlPane
Constructor based on a url represented by a string.- Parameters:
url
- the URL that the pane should initially display- Throws:
IOException
- an error setting the page occured.
-
HtmlPane
Constructor based on a url.- Parameters:
url
- the URL that the pane should initially display- Throws:
IOException
- an error setting the page occurred.
-
-
Method Details
-
setLocale
-
setContentLocale
Set the local of the content pane. This method allows the locale of the content panes (the HTML pane) to be set without changing the layout of navigation controls.- Parameters:
locale
- the locale.
-
getContentPaneBorder
Get the border for this component's contents.- Returns:
- the border
-
setContentPaneBorder
Set the border for this component's contents.- Parameters:
border
- the border
-
setPage
Set the page to display and display it.- Parameters:
page
- the URL of the page to display.- Throws:
IOException
- an error occurred reading the page.
-
setPage
Set the page to display and display it.- Parameters:
page
- the URL of the page to display.- Throws:
IOException
- an error occurred reading the page.
-
setBackground
Set the background color. This method will also set the background color of scroll bars unless the last call tosetScrollbarBackground(Color)
, if one was made, had a non-null argument.Note: with some pluggable look and feels, this method may be fully or partially ignored. It works as expected with the default look and feel.
- Overrides:
setBackground
in classJComponent
- Parameters:
color
- the color
-
setScrollbarBackground
Set the background color for scroll bars. If color is null and the last call tosetBackground(Color)
, if one was made, had a non-null argument, that background color will be used. If the last call tosetBackground(Color)
had a null argument, the color passed as an argument will be used.Note: with some pluggable look and feels, this method may be fully or partially ignored. It works as expected with the default look and feel.
- Parameters:
color
- the color; null for the default color as modified by the last call (if any) tosetBackground(Color)
-
getPage
get the URL for the page being displayed.- Returns:
- the URL for the page being displayed; null if there is none.
-
setErrorTitle
Set the title to use in error message dialog boxes. This title will be used as a title for various dialog boxes.- Parameters:
title
- the title to display; null to use the default (which is locale specific)
-
getErrorTitle
Get the title used in error message dialog boxes.- Returns:
- the current title.
-
setComponentOrientation
- Overrides:
setComponentOrientation
in classComponent
-
setButtonBackground
Set the background color for the 'start', 'back', 'reload', 'forward', and 'end' controls. When rvmode is true, the icons will be white when enabled and grey when disabled, the reverse from the normal behavior.Note: with some pluggable look and feels, this method may be fully or partially ignored. It works as expected with the default look and feel.
- Parameters:
color
- the colorrvmode
- true for reverse video; false otherwise
-
isEditable
public boolean isEditable()Determine if this HtmlPane is editable.- Returns:
- true if it is editable; false otherwise
-
setEditable
public void setEditable(boolean value) Set whether or not this HtmlPane is editable. This method sets a property of the underlying JEditorPane.When editable, one can add text, but to format it a subclass will be needed. When editing, links will not function and the text will not be modifiable.
- Parameters:
value
- true if this pane is to be editable; false otherwise
-
setCaretColor
Set the color of the caret. The caret (by default a blinking vertical line) will normally be black. It should be set to white if the background will be dark.- Parameters:
c
- the color for the caret
-