Right now i’m working on JavaHelp content.
Basically, First solution, after you select the the selected function from the tree menu or node (JTree), and pressed help key (F1) it will popup the specific JavaHelp content based on selected node.
Right now, im trying to add Help button, user first need to select function from the tree menu or node and click on Help button i created. it suppose work exactly as the first solution but right now, it doesn’t popup the correct content.
How can i make the Help button to trigger the F1 key action? meaning when we select the node, it already have a focus n can directly popup if we pressed F1 key, the help button would probably just trigger the F1 key action.
I heard about doClick function or keys binding, any ideas on this?
Thanks
Regards,
Aznimah
Hi, i try to implement the keybinding to trigger the F1 key action when user click on Help button. But i clueless how to set code to trigger the F1 key action. Here is some code :
action button:
final String helpIconLocation = new String("/icons/help_new.png");
iconResource = CustomizedToolbar.class.getResource(helpIconLocation);
icon = new ImageIcon(iconResource);
actionButton = new JButton(icon);
actionButton.setFocusable(false);
actionButton.addActionListener(new JavaHelpHandler());
ActionListener:
private class JavaHelpHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
Action javaHelpF1KeyAction = new AbstractAction();
KeyStroke helpKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
MainApp.getMainAppPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
helpKeyStroke, "F1");
MainApp.getMainAppPanel().getActionMap().put("F1", javaHelpF1KeyAction);
}
}
private class AbstractAction implements ActionListener, Action {
@Override
public void actionPerformed(ActionEvent e) {
// TO display popup javaHelp content
HelpSystemUtil.getInstance().enableHelpFromFocus(actionButton);
}
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
// TODO Auto-generated method stub
}
@Override
public Object getValue(String key) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isEnabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public void putValue(String key, Object value) {
// TODO Auto-generated method stub
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void setEnabled(boolean b) {
// TODO Auto-generated method stub
}
}
How can i set actionMap to trigger the F1 keys action? really need help on this
thanks
The best way you could do is to create a Key Listener.
KeyListener
There are several ways to do this. Here’s one:
yourComponent.addKeyListener(new KeyAdapter () { @Override public void keyPressed(KeyEvent e) { if ( e == YOUR_KEY_CODE ) { // Do something } } });Anyway, key code for F1 is 112