- All Implemented Interfaces:
ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,Accessible
,MenuElement
,SwingConstants
HtmlWithTocPane
.
Once the frame is created, it will persist for the lifetime of an application. Closing a window simply makes the frame invisible. This allows the help window to maintain its state as the application runs. Constructors may also provide a resource-bundle name and keys for the menu-item title, URL, and help-frame title.
If some or all of the Help HTML files are stored in an
application's JAR file or JAR files, on can use the "sresource" or
"resource" URL scheme to access them. In this case one should call
the method Handlers.enable()
in order
to enable the "resource" and "sresource" URL schemes. It may also
be necessary to set some Java properties (e.g., with the java -D
option).
As an example, Suppose the file toc.xml is accessed using the URL file:///PATH/toc.xml, where PATH should be replace by a path from the root directory to the directory that contains toc.xml, and that toc.xml contains the following:
Also suppose that the file manual.html is accessed using the URL file:///PATH/manual.html and that manual.html is an HTML 3.2 file with anchors names "gui", "output", "request", "prefs", menus", and "terminal". Then the following code will create on-line help for an application and make it accessible from a "Help" menu.<?xml version="1.0" ?> <!DOCTYPE toc SYSTEM "sresource:/org/bzdev/swing/toc.dtd"> <toc> <node title="table of contents" uri="file:///PATH/manual.html" > <node title="chapter1" uri="file:///PATH/manual.html#gui" /> <node title="chapter2" uri="file:///PATH/manual.html#output" > <node title="Section1" uri="file:///PATH/manual.html#request" /> <node title="Section2" uri="file:///PATH/manual.html#prefs" /> <node title="Section3" uri="file:///PATH/manual.html#menus" /> </node> <node title="chapter3" uri="file:///PATH/manual.html#terminal" /> </node> </toc>
Other constructors can be used when internationalization is needed. For a HelpMenuItem, the internationalized constructors uses a resource bundle to look up the titles and uris based on a locale.JFrame frame = new JFrame("Application"); JMenuBar menubar = new JMenuBar(); ... JMenuItem helpMenuItem = new HelpMenuItem("Help", "file:///PATH/toc.xml", "Help", 800, 600); JMenu helpMenu = new JMenu("Help"); helpMenu.add(helpMenuItem); menubar.add(helpMenu); ... frame.setJMenuBar(menubar); ...
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItem
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
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
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
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
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
Constructor Summary
ConstructorsConstructorDescriptionHelpMenuItem
(String menuItemName, String url, String title, int xsize, int ysize) Constructor.HelpMenuItem
(String menuItemName, String url, String title, int xsize, int ysize, String dmURL) Constructor with a dark mode option.HelpMenuItem
(String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize) Constructor using resource bundles.HelpMenuItem
(String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize, String dmUrlKey) Constructor using resource bundles with a dark mode option.HelpMenuItem
(Locale locale, String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize) Constructor given a locale and resource bundle.HelpMenuItem
(Locale locale, String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize, String dmUrlKey) Constructor given a locale and resource bundle with a dark mode option. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Set the locale.Methods inherited from class javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getAccessibleContext, getComponent, getMenuDragMouseListeners, getMenuKeyListeners, getSubElements, getUIClassID, init, isArmed, menuSelectionChanged, paramString, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setAccelerator, setArmed, setEnabled, setModel, setUI, updateUI
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, 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, 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, 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
-
Constructor Details
-
HelpMenuItem
public HelpMenuItem(String menuItemName, String url, String title, int xsize, int ysize) throws IOException Constructor.- Parameters:
menuItemName
- the name to use in the menu item createdurl
- the URL for the help-frame's HTML or XML filetitle
- the title of the help framexsize
- the horizontal size of the frame in pointsysize
- the vertical size of the frame in points- Throws:
IOException
- the URL could not be loaded
-
HelpMenuItem
public HelpMenuItem(String menuItemName, String url, String title, int xsize, int ysize, String dmURL) throws IOException Constructor with a dark mode option.- Parameters:
menuItemName
- the name to use in the menu item createdurl
- the URL for the help-frame's HTML or XML filetitle
- the title of the help framexsize
- the horizontal size of the frame in pointsysize
- the vertical size of the frame in pointsdmURL
- the help-frame's URL for dark mode.- Throws:
IOException
- the URL could not be loaded
-
HelpMenuItem
public HelpMenuItem(String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize) throws IOException Constructor using resource bundles. A resource bundle is used to look up the menu-title, help-frame URL, and help-frame title, from keys, with the names of the keys provided as arguments.- Parameters:
bundleName
- the name of the resource bundle used to configure the help frame.menuItemNameKey
- the bundle's key for the title to use in the menu item createdurlKey
- the bundle's key for the URLtitleKey
- the bundle's key for the title of the help framexsize
- the horizontal size of the help frame in pointsysize
- the vertical size of the help frame in points- Throws:
IOException
- the URL could not be loaded
-
HelpMenuItem
public HelpMenuItem(String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize, String dmUrlKey) throws IOException Constructor using resource bundles with a dark mode option. A resource bundle is used to look up the menu-title, help-frame URL, and help-frame title, from keys, with the names of the keys provided as arguments.- Parameters:
bundleName
- the name of the resource bundle used to configure the help frame.menuItemNameKey
- the bundle's key for the title to use in the menu item createdurlKey
- the bundle's key for the URLtitleKey
- the bundle's key for the title of the help framexsize
- the horizontal size of the help frame in pointsysize
- the vertical size of the help frame in pointsdmUrlKey
- the bundle's key for the content's dark-mode URL- Throws:
IOException
- the URL could not be loaded
-
HelpMenuItem
public HelpMenuItem(Locale locale, String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize) throws IOException Constructor given a locale and resource bundle. A resource bundle is used to look up the menu-title, help-frame URL, and help-frame title, from keys, with the names of the keys provided as arguments.- Parameters:
locale
- the localebundleName
- the name of the resource bundlemenuItemNameKey
- the bundle's key for the title to use in the menu item createdurlKey
- the bundle's key for the content's URLtitleKey
- the bundle's key for the title of the help framexsize
- the horizontal size of the help frame in pointsysize
- the vertical size of the help frame in points- Throws:
IOException
- the URL could not be loaded
-
HelpMenuItem
public HelpMenuItem(Locale locale, String bundleName, String menuItemNameKey, String urlKey, String titleKey, int xsize, int ysize, String dmUrlKey) throws IOException Constructor given a locale and resource bundle with a dark mode option. A resource bundle is used to look up the menu-title, help-frame URL, and help-frame title, from keys, with the names of the keys provided as arguments.- Parameters:
locale
- the localebundleName
- the name of the resource bundlemenuItemNameKey
- the bundle's key for the title to use in the menu item createdurlKey
- the bundle's key for the content's URLtitleKey
- the bundle's key for the title of the help framexsize
- the horizontal size of the help frame in pointsysize
- the vertical size of the help frame in pointsdmUrlKey
- the bundle's key for the content's dark-mode URL- Throws:
IOException
- the URL could not be loaded
-
-
Method Details
-
setLocale
Set the locale. -
setComponentOrientation
- Overrides:
setComponentOrientation
in classComponent
-