on pressed event in radio button compare in form itself

61 views Asked by At
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

0

There are 0 answers