0

I have a data entry form with 3 buttons: "Save/Next", "Clear" and "Exit". I want the Save/Next button to perform its own function, then finish by setting the focus to the Clear button and causing it to execute, reset all the text fields to be ready for the next set of data. I was hoping to avoid copying all the clearing code lines into the event handler for the Save button.

Is there an easy way to programmatically create the event that the Clear button eventHandler recognizes (ENTER key in this case), thus executing without user input?

  btnClear.setOnAction(new EventHandler<ActionEvent>() {
     @Override
     public void handle(ActionEvent event) {
        barcodeText1.clear();
        barcodeText2.clear();
        //
        // more clearing statements here...
        //
        statusContent.setText(stStatusTextScan1);
        barcodeText1.requestFocus(); //return focus to first field
     }// end handle
  });//end btnClear

// Save Button Event Handler ..............................................
 btnSave.setOnAction(new EventHandler<ActionEvent>() {
     @Override
     public void handle(ActionEvent event) {
        //
        // Do some Saving stuff...
        //

        // Record saved. Now reset the form for the next record...
        btnClear.requestFocus();

        // Put something here that will mimick pressing ENTER key...
        Event e = new Event(<KeyEvent>);

     }// end handle
  });// end btnSave
fabian
  • 80,457
  • 12
  • 86
  • 114

1 Answers1

0

Berger: Good find. btnClear.fire() in your link worked like a charm for me. There is an art to finding the best search term combinations which I have not yet mastered. Thanks.