简体   繁体   中英

JavaFX setOnKeyTyped event firing before text field updated

   txfInput.setOnKeyTyped(
        e -> {
            if(group.getSelectedToggle() == rdEncrypt){
                txfOutput.setText(en.encryptText(txfInput.getText()));
            }else if(group.getSelectedToggle() == rdDecrypt){
                txfOutput.setText(en.decryptText(txfInput.getText()));
            }
        }
    );

In the following code, the text that gets passed to the encryptText method is the text before the key was pressed. I am curious how to update the txfInput before the code gets run.

Sorry - all I had to do was change onKeyTyped to onKeyReleased

 txfInput.setOnKeyTyped -> txfInput.setOnKeyReleased

Thank You @sedrick-jefferson!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM