Apache NetBeans Wiki Index

Note: These pages are being reviewed.

How can I override JavaHelp to display my own help or documentation?

  1. How can I override JavaHelp to display my own help or documentation?

  2. Step 1: HelpCtx.Displayer

  3. Step 2: Help.class

  4. Step 3: Connecting UI To JavaHelp

  5. Step 4: Add the JavaHelp Integration Module

  6. Summary: Putting It All Together

  7. Apache Migration Information

Step 1: HelpCtx.Displayer

First, you must create a HelpCtx.Displayer that is capable of displaying your help and register it as a service provider

    @ServiceProvider(service = HelpCtx.Displayer.class, position = 1000)
public class CustomHelpDisplayer implements HelpCtx.Displayer {

    public boolean display(final HelpCtx helpCtx) {

        // Put your displaying code here.

        return true;

Step 2: Help.class

An instance of org.netbeans.api.javahelp.Help determines what to do with a particular HelpCtx. In order to use your custom help displayer, you need to create an instance of Help that can display using your custom help displayer. In this case, you want to override the Help class provided with the NetBeans platform, so you set the 'position' attribute low. The purpose of this class is two-fold:

  • If the HelpCtx.getHelpID() is a value we recognize and can use, we display it with our displayer. For our example below, we handle any help ID that starts with "PREFIX."

  • If not, we pass it on to the default help system.

    @ServiceProvider(service = Help.class, position = 1)
public class CustomHelp extends Help {

    public Boolean isValidID(final String id, final boolean force) {
        // We return true because even if it's not a valid ID for our purposes, we just pass it
        // to the default help and let it deal with it.
        return true;

    public void showHelp(final HelpCtx ctx, final boolean showmaster) {

        // Here, we examine the ID and if it starts with "PREFIX", we find our implementation
        // of HelpCtx.Displayer using the Lookup API and use it to display our help.
        if (ctx.getHelpID().startsWith("PREFIX")) {

            final HelpCtx.Displayer displayer =


        // If we don't know what do with the ID, we find all the implementations of Help and
        // pass the HelpCtx along to the first one we find that isn't this class.
        else {
            final Collection<? extends Help> helps =

            for (Help help : helps) {
                if (help != this) {
                    help.showHelp(ctx, showmaster);


    public void addChangeListener(final ChangeListener listener) {
        // *** Not sure what to do here.

    public void removeChangeListener(final ChangeListener listener) {
        // *** Not sure what to do here.

Step 3: Connecting UI To JavaHelp

Step 4: Add the JavaHelp Integration Module

This module is not "eager", so to force it to load, at least one module must depend on it. Simply make JavaHelp Integeration a dependency of one your modules to make Help available. The JavaHelp Integration module is in the 'platform' library.

Summary: Putting It All Together

  • Your UI provides the HelpCtx.

  • The CustomHelp class (invoked when the user launches help, usually by pressing F1) examines help IDs.

  • If it’s one we recognize, we invoke our custom displayer.

  • If it’s not, we hand it off to another Help instance.

Applies to: NetBeans IDE 7.2 Platforms: All

=== Apache Migration Information

The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.

This page was exported from http://wiki.netbeans.org/DevFaqJavaHelpOverrideCustom , that was last modified by NetBeans user Michael.Bishop on 2013-03-08T19:33:37Z.

NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.