1 Reply Latest reply on Aug 14, 2008 3:54 AM by 843810

    javahelp doesnt display

    843810
      I have a simple javahelp example that works for me

      I tried to put it into a working application though and it does not display the java help any more.

      Here is what I am doing in the one that works:
              public helpTest() {
                f = new JFrame("Menu Example");
                JMenuBar mbar = new JMenuBar();
                
                // a file menu
                JMenu file = new JMenu("File");
                JMenu help = new JMenu("Help");
      
                // add an item to the help menu
                help.add(topics = new JMenuItem("Help Topics"));
      
                // add the menu items to the menu bar
                mbar.add(file);
                mbar.add(help);
      
                try {
                     
                     HelpSet hs = getHelpSet("help.hs"); 
                     HelpBroker hb = hs.createHelpBroker();
      
                     topics.addActionListener(new CSH.DisplayHelpFromSource(hb));
      
                     // attach menubar to frame, set its size, and make it visible
                     f.setJMenuBar(mbar);
                     f.setSize(500, 300);
                     f.setVisible(true);
                     
                }catch(Exception e) {
                     e.printStackTrace();
                }
              }
      
              /**
               * find the helpset file and create a HelpSet object
               */
              public HelpSet getHelpSet(String helpsetfile) {
                 HelpSet hs = null;
                 ClassLoader cl = this.getClass().getClassLoader();
                 try {
                   URL hsURL = HelpSet.findHelpSet(cl,  helpsetfile);
                   hs = new HelpSet(null, hsURL);
                 } catch(Exception ee) {
                      ee.printStackTrace();
                   System.out.println("HelpSet: "+ee.getMessage());
                   System.out.println("HelpSet: "+ helpsetfile + " not found");
                 }
                 return hs;
              }
      in the one that does not work, I am doing:
           public void viewHelp() {
                
                try {
                     
                     System.out.println("defining help");
                     // 1. create HelpSet and HelpBroker objects
                     HelpSet hs = getHelpSet("help.hs"); 
                     
                     HelpBroker hb = hs.createHelpBroker();
      
                     if (hb != null){
                          System.out.println("launching help");
                          new CSH.DisplayHelpFromSource(hb);
                         
                          System.out.println("done launching help");
                     } else {
                          System.out.println("error launching help");
                     }
                     
                     //// 2. assign help to components
                     //CSH.setHelpIDString(topics, "top");
                     
                     // 3. handle events
                     //topics.addActionListener(
      
                     
                }catch(Exception e) {
                     e.printStackTrace();
                }
      
           }
           
              /**
               * find the helpset file and create a HelpSet object
               */
              public HelpSet getHelpSet(String helpsetfile) {
                 HelpSet hs = null;
                 ClassLoader cl = this.getClass().getClassLoader();
                 try {
                          System.out.println("looking for " + helpsetfile + " in our classpath" );
      
                      URL hsURL = HelpSet.findHelpSet(cl,  helpsetfile);
                     hs = new HelpSet(null, hsURL);
                          System.out.println("got " + hs.getTitle() );
                      return hs;
                 } catch(Exception ee) {
                      ee.printStackTrace();
                 }
              System.out.println("error getting helpset");
                 return null;
              }
      All it does is print:

      defining help
      looking for help.hs in our classpath
      got help
      launching help
      done launching help

      so between "launching help" and "done launching help" the help window never appeared.

      I think it has to be in the classpath as it returns "got help" which it got from the object itself.

      Can anyone explain what might be going on or how to troubleshoot it?
        • 1. Re: javahelp doesnt display
          843810
          ok, I feel silly now.

          I thought new CSH.DisplayHelpFromSource(hb) launched the code

          So, I created an action listener and called helpTest() from in my action listener.

          So my action listener was calling code that made another action listener...

          I changed it now so my code is:
               public ActionListener getHelpListener() {
                    
                    try {
                         
                         HelpSet hs = getHelpSet("help.hs"); 
                         HelpBroker hb = hs.createHelpBroker();
          
                         if (hb != null){
                              return new CSH.DisplayHelpFromSource(hb);
                         }
                    }catch(Exception e) {
                         e.printStackTrace();
                    }
                    return null;
               }
          then I add add my menu as:
                              ActionListener helper = getHelpListener();
                              jMenuHelp.add(jMenuHelpContents);
                              jMenuHelpContents.addActionListener(helper);
          and now it works fine