F1 JavaHelp key


In any program or application, most of the times when pressing the F1 key, a help system is opened referring to that utility.

I am in my project and I have created a help system, which should be opened by pressing F1 but not ... 1) Fail to press F1, it does not do anything.

2) I have a menu with a button and open the help system by clicking twice.


private void lanzarAyuda(){
            //Carga el fichero de ayuda.
            File fichero = new File("sistema_ayuda" + File.separator + "helpset.hs");
            URL hsURL = fichero.toURI().toURL();

            //Crea el HelpSet.
            HelpSet helpset = new HelpSet(getClass().getClassLoader(), hsURL);
            HelpBroker hb = helpset.createHelpBroker();
            //Mostrar el sistema de ayuda al pulsar F1.
            hb.enableHelpOnButton(button_ayuda, "principal", helpset);
            hb.enableHelpKey(getRootPane(), "principal", helpset);

            //Colocamos la posicion de la ventana (Posicion p).
            hb.setSize(new Dimension(800,600));
            //Colocamos el tamaño de la ventana (Dimension d).
            hb.setLocation(new Point(250,90));
        }catch(Exception e){

private void button_ayudaActionPerformed(java.awt.event.ActionEvent evt) {                                             
asked by omaza1990 08.01.2017 в 22:11

1 answer


As for your failure to do anything when pressing F1, it could be because the System is not recognizing the corresponding Key press. You can try adding the following method to your program:

public static void addF1ListenerWindowDialog() 
   ActionListener F1Action = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //Todo lo que quieres que haga al pulsar F1
    KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0),
answered by 08.01.2017 / 22:42