0
private void DishFormWeekNoWeek1RbKeyTyped(java.awt.event.KeyEvent evt) {                                               
        // TODO add your handling code here:
        char character = evt.getKeyChar();
        //System.out.print("Number:"+number + "character:"+character);
        if(character == KeyEvent.VK_1){
            System.out.print("character:"+character);
            DishFormWeekNoWeek1Rb.setSelected(true);
            DishFormWeekNoWeek1Rb.requestFocus(true);
        }else if(character == KeyEvent.VK_2){
            System.out.print("character:"+character);
            DishFormWeekNoWeek2Rb.setSelected(true);
            DishFormWeekNoWeek2Rb.requestFocus(true);
        }else if(character == KeyEvent.VK_3){
            System.out.print("character:"+character);
            DishFormWeekNoWeek3Rb.setSelected(true);
            DishFormWeekNoWeek3Rb.requestFocus(true);
        }else if(character == KeyEvent.VK_4){
            System.out.print("character:"+character);
            DishFormWeekNoWeek4Rb.setSelected(true);
            DishFormWeekNoWeek4Rb.requestFocus(true);
        }

    }

Radio button adding short cut key

private void formKeyPressed(java.awt.event.KeyEvent evt) {                                
        // TODO add your handling code here:
        char character = evt.getKeyChar();
        //System.out.print("Number:"+number + "character:"+character);
        if(character == KeyEvent.VK_1){
            System.out.print("character:"+character);
            DishFormWeekNoWeek1Rb.setSelected(true);
            DishFormWeekNoWeek1Rb.requestFocus(true);
        }else if(character == KeyEvent.VK_2){
            System.out.print("character:"+character);
            DishFormWeekNoWeek2Rb.setSelected(true);
            DishFormWeekNoWeek2Rb.requestFocus(true);
        }else if(character == KeyEvent.VK_3){
            System.out.print("character:"+character);
            DishFormWeekNoWeek3Rb.setSelected(true);
            DishFormWeekNoWeek3Rb.requestFocus(true);
        }else if(character == KeyEvent.VK_4){
            System.out.print("character:"+character);
            DishFormWeekNoWeek4Rb.setSelected(true);
            DishFormWeekNoWeek4Rb.requestFocus(true);
        }
    }

I have same code for adding short cut key in radio button and in form itself but in the form itself it does not fire...How to write it in a way that it will fire whenever i press the number even when i dont select the button..Basically i want to have a short key that when i press it it will select and focus that component

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Brownman Revival
  • 3,620
  • 9
  • 31
  • 69
  • i keep trying on making the mnemonic thing for hours now but i cant make it if i was able to make it then i would not have come up with just a work around..i want the mnemonic but in my current level i cant do so i am doing the work around.. – Brownman Revival Nov 17 '14 at 11:01
  • my question is after adding the mnemonic how should i put the keyevent that will call that nmemonic... a sample will really make it easy to understand – Brownman Revival Nov 17 '14 at 11:11
  • I know that that, this is the minimum code i came up with using this approach the only question for me is how can i fire the Key Event from the form itself if i can come up with a solution for this i can fix it using the way i code it can you give suggestion on this? or how to make the radiogroup sa nextfocusablecomponent – Brownman Revival Nov 17 '14 at 11:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65069/discussion-between-hogrider-and-andrew-thompson). – Brownman Revival Nov 17 '14 at 11:20
  • 2
    As outlined in [How to Use Buttons, Check Boxes, and Radio Buttons](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html) (the first example clearly demonstrates it), you can use something like `b1.setMnemonic(KeyEvent.VK_D);`, which, when triggered, will call the buttons associated `ActionListener`... – MadProgrammer Nov 17 '14 at 11:45
  • ive been trying it yesterday if it wasnt for your link i wasnt not able to read that it need to has alt i mean press `alt` with letter – Brownman Revival Nov 18 '14 at 02:41

0 Answers0