I have an application consisting of five components. Each one extends JPanel. If I want to press F1 in my application and bring up help, I can do the following:
where parent is the top level of the application (extends JFrame)
What I would like is if JPanel 1 has focus, pressing F1 would bring up JavaHelp at the TOC entry for panel 1. Likewise, F1 would bring up the appropriate help entry if pressed in the other four panels.
I've tried to go through the Oracle documentation, but it makes no sense to me. I tried this:
where parent.getPanel1() returns the instance of my Panel1 extended JPanel class. I get an error: java.lang.IllegalArgumentException: Invalid Component
I get no error when I use:
from within the class (also extends JPanel) that these commands are included in. But F1 does nothing, so not much of an improvement.
Has anyone tried this, and if so, could you give me some pointers as to how it is supposed to work?
When F1 is pressed while that component, or one of its children, has the focus, the JavaHelp viewer will appear displaying the appropriate help topic. If a child component has the focus and has an associated help ID assigned, the help viewer will display the help topic specific to that component. Otherwise the default topic (specified as "MyTopicID" above) will be displayed."
So my understanding was that I had to do three things:
1. create a help broker
2. assign a help ID to a child component
3. enable the help key on the root pane
But I must be wrong about that, because for step 2, I get-
so I am not getting why it is not working on my instance of JPanel. I assume I either have the wrong method for assigning a help id to a component or I am not specifying the component correctly, but I'm at a loss to know which. I've not found a example, just snippets that usually left out step 2.
but I get the same error. I think that method is supposed to be used for buttons and menu items.
I've not found any discussion on assigning a help ID that actually includes what method to use and the discussions usually just repeat the same unhelpful recipe almost verbatim from one to the next.
So could someone with some javahelp expertise set me straight?
Joined: Oct 10, 2011
This seems to work OK, though I had to add a mouse listener to give the panel focus when I clicked in it, other than in the text fields. I didn't include the help set, but "top", "left" and "right" are defined in the help.jhm file of the helpset.