Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:49:34+00:00 2026-05-14T02:49:34+00:00

When I use HelpBroker.setCurrentID([some help id]) , JavaHelp correctly shows the page I want

  • 0

When I use HelpBroker.setCurrentID("[some help id]"), JavaHelp correctly shows the page I want but the associated topic is not automatically selected/highlighted in the table of contents. This makes it difficult for a user to know where in the topic tree the current page is located.

Is there any way to programmatically highlight the current topic in the TOC when I use a HelpBroker to navigate to a specific Help page?

Note that when the user follows links within the Java help system, the new topic is properly selected in the table of contents.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:49:34+00:00Added an answer on May 14, 2026 at 2:49 am

    You should be able to just call the navigate() function, the rest are helpers. id is the id of course, and nodeLabel is the visible text on the node you want to select. Do note that this code doesn’t check for errors, namely preventing trying to go somewhere that doesn’t exist.

    import java.awt.Component;
    import java.util.Enumeration;
    import javax.help.*;
    import javax.help.plaf.basic.BasicTOCNavigatorUI;
    import javax.swing.JTree;
    import javax.swing.JScrollPane;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.DefaultMutableTreeNode;
    
    public class Nav
    {
        private static DefaultMutableTreeNode match = null;
    
        private Nav()
        {
        }
    
        public static void navigate(HelpSet set, HelpBroker broker, String id, String nodeLabel)
        {
            broker.setCurrentID(id);
            JHelp jhelp = new JHelp(set);
            JHelpNavigator nav = getNavigator(jhelp);
            JTree tree = getTree(nav);
            TreeModel model = tree.getModel();
            Object root = model.getRoot();
            match = null;
            findNode(model, root, nodeLabel);
            TreePath path = new TreePath(match.getPath());
            tree.setSelectionPath(path);
            tree.scrollPathToVisible(path);
        }
    
        //http://www.google.com/codesearch/p?hl=en#WiboLAWeTd0/xena/ext/src/javahelp/jhMaster/JavaHelp/src/new/javax/help/WindowPresentation.java&t=0&d=30&l=272
        private static JHelpNavigator getNavigator(JHelp jhelp)
        {
            JHelpNavigator nav = null;
            for (Enumeration e = jhelp.getHelpNavigators(); e.hasMoreElements(); ) 
            {
                nav = (JHelpNavigator) e.nextElement();
                if (nav.getNavigatorName().equals("TOC"))
                {
                    return nav;
                }
            }
            return null;
        }
    
        //http://forums.sun.com/thread.jspa?threadID=350180#1459484
        private static JTree getTree(JHelpNavigator nav)
        {
            JTree tree = null;
            Component[] components = nav.getComponents();
            int count = components.length;
            int i = 0;
            while(i < count && !(components[i] instanceof JScrollPane))
            {
                i++;
            }
            if(i < count)
            {
                JScrollPane sp = (JScrollPane) components[i];
                components = sp.getViewport().getComponents();
                count = components.length;
                i = 0;
                while(i < count && !(components[i] instanceof JTree))
                {
                    i++;
                }
                tree = (JTree) components[i];
            }
            return tree;
        }
    
        //http://www.rkcole.com/articles/swing/TraverseJtree-2000-11-17.html
        private static void findNode(TreeModel model, Object o, String search)
        {
            if(match != null)
                return;
    
            int count = model.getChildCount(o);
            for( int i=0;  i < count;  i++ )
            {
                Object child = model.getChild(o, i );
                if (  model.isLeaf( child ) )
                {
                    if(search.equals(((TOCItem)((DefaultMutableTreeNode)child).getUserObject()).getName()))
                    {
                        match = (DefaultMutableTreeNode)child;
                        return;
                    }
                }
                else
                    findNode( model, child, search );
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Firebug and the Mozilla JS console heavily, but every now and then
I use a stream reader to import some data and at the moment I
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated
We use a data acquisition card to take readings from a device that increases
I use rsync to synchronize files to Windows clients in a server agnostic way.
I use emacs to edit my xml files (nxml-mode) and the files were generated
I use the VS2008 command prompt for builds, TFS access etc. and the cygwin
We use QuickBooks for financial management, and feed it from a variety of sources.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.