Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can javahelp be invoked on JPanels?

 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyBindings with the correct inputmap should do what you want
 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this from a java book

"abstract interface javax.help.HelpBroker

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-

java.lang.IllegalArgumentException: Invalid Component

enableHelp:

enableHelp(java.awt.Component comp, java.lang.String id, HelpSet hs)
Enables help for a component.

JPanel:

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel

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.

I also tried-

hb.enableHelpKey(myComponent, "componentTopic", hs);

but I get the same error.

and I tried:

CSH.setHelpIDString(myComponent,"componentTopic");

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?

 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Swanson wrote:I had to add a mouse listener to give the panel focus when I clicked in it

Just guessing here, but possibly all you needed was setFocusable(true). A JPanel isn't focusable by default.
 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gave that a try. I replaced:


with


same for the other two panels. I could not click in the panel and get focus on the panel and so the wrong help comes up. I actually seem to need to request focus.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic