0

I have no idea why this isn't working. Netbeans does not allow me to edit this portion of the code.

        deletestudentButton.setText("Delete Student");
    deletestudentButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            deletestudentButtonActionPerformed(evt);
        }
    });
    deletestudentButton.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            deletestudentButtonKeyPressed(evt);
        }
    });

However when go in to the Events in design mode and select keyPressed it gives me the following:

private void deletestudentButtonKeyPressed(java.awt.event.KeyEvent evt) {                                               

     deletestudentButton.setMnemonic(KeyEvent.VK_R);
     deletestudentButton.setMnemonic(evt.VK_R);
      deletestudentButton.addKeyListener(new java.awt.event.KeyAdapter() {

    }                                              

I figured thats where I should SetMnemonic. I tried two different statements, but when it compiles it does not initiate the keypress.

D_DOT
  • 1
  • 3
  • 1
    Do not use KeyListeners. At all. Right after you *create* the button, call its setMnemonic method. Nothing else should be needed. However, the mnemonic has to be a character that’s in the button’s text, so `KeyEvent.VK_R` won’t work. Try `KeyEvent.VK_D` instead. – VGR Jun 06 '18 at 19:12
  • I got it to work! It was in the Properties of the Button itself in design mode. – D_DOT Jun 06 '18 at 19:16
  • Now to figure out how to get ctrl+d to work – D_DOT Jun 06 '18 at 19:17
  • Does your window have a menu bar? – VGR Jun 06 '18 at 19:17
  • a combobox? yes – D_DOT Jun 06 '18 at 19:43
  • *"Now to figure out how to get ctrl+d to work"* - Add a [key binding](https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html) to the button – MadProgrammer Jun 06 '18 at 19:50
  • The mnemonic allows Alt-D to activate your button. Why do you also need Ctrl-D to activate it? – VGR Jun 06 '18 at 20:26
  • It is part of an assignment I am doing for my Java class. – D_DOT Jun 07 '18 at 03:46

0 Answers0