Embedding JavaHelp Components

JavaHelp system components can be embedded directly into the application. The following pared down steps are taken from the idedemo sample program included with the JavaHelp software release. A TOC navigator is added to the main application frame and the content pane is added to a tabbed display at the bottom of the main application frame. You can find the complete sources for the sample program at:

      demos\src\sunw\demo\idedemo
  1. Find the helpset file and create the HelpSet object:
    try {
           ClassLoader cl = ApiDemo.class.getClassLoader();
           URL url = HelpSet.findHelpSet(cl, "api");
           apiHS = new HelpSet(cl, url);
       } catch (Exception ee) {
           System.out.println ("API Help Set not found");
           return;
       }
  2. Create the content pane:
    JHelpContentViewer viewer1 = new JHelpContentViewer(apiHS);
    	
  3. Add the content pane to a container:
    messages.setComponentAt(miscTabIndex, viewer1);
    messages.setSelectedIndex(miscTabIndex);
    
  4. Create a navigator (TOC):
    xnav = (JHelpNavigator) apiHS.getNavigatorView("TOC").createNavigator(viewer1.getModel());
  5. Use the same model for both the content pane and navigator components (viewer1) to ensure that changes generated by one component are reflected in the other component. Note that the TOC can be created by using either the HelpSet.getNavigatorView() method or the JavaHelpNavigator.getNavigatorView() method. Both methods produce the same results; however, using HelpSet reduces the dependency on the GUI.


  6. Add the navigator to the container:
    content.add(xnav, "Center");
    classViewerIFrame.setContentPane(content);

See also:

Programming with the JavaHelp System
Adding the JavaHelp System to Applications
Implementing Context-Sensitive Help