Invoking Help with a Button, Menu Item, or Key

The simplest online help addition to any application is a menu item that starts the help system. Typically, a Help menu item is not context-sensitive: the help system always opens with the default help topic specified in the HelpSet file. The user can manually navigate through the TOC or search through the index or word-search index for other help topics.

Other standard ways to start the help system include clicking a Help button and pressing a Help key (by custom, function key F1). It’s up to you to decide which mechanism(s) to use. Follow these steps to add all three help activators to the TypeFacer example: menu item, button, and function key. Instead of writing new lines of code, you just need to uncomment (that is, remove the comment indicators from) lines that are already there. For this revision of the program, all the lines to be uncommented start with //#1. Use your text editor’s search command to locate these lines.

  1. Import the Java class library for JavaHelp:

    import javax.help.*;
  2. Create new instance variables for HelpSet-level classes, and for the Help menu item and Help button:

    HelpSet hs;
    HelpBroker hb;
    ...
    JButton    helpButton;
     ...
    JMenu helpMenu;
    JMenuItem helpItem;
  3. Create the Help menu item and button objects themselves:

    helpButton = new JButton("Help");
     ...
    buttonPanel.add(helpButton);
     ...
    helpMenu = new JMenu("Help");
    helpItem = new JMenuItem("Contents...");
    helpMenu.add(helpItem);
    ...
    menuBar.add(helpMenu);
  4. Activate the ...

Get Creating Effective JavaHelp now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.