F1 JavaHelp key

2

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.

Code:

private void lanzarAyuda(){
        try{
            //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){
            e.printStackTrace();
        }
    }

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

1 answer

2

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() {
    @Override
        public void actionPerformed(ActionEvent e) {
            //Todo lo que quieres que haga al pulsar F1
        }
    };
    windowDialog.getRootPane().registerKeyboardAction(F1Action,
    KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0),
    JComponent.WHEN_IN_FOCUSED_WINDOW);
}
    
answered by 08.01.2017 / 22:42
source