Order of Listeners Events

Asked

Viewed 188 times

0

I have a tableView with a Listener when selecting a new table view row, and I have a textfield that receives a value from one of the tableView columns;

textfield has a listener when losing the focus of the field it updates the value of the selected line in the tableview;

The problem occurs when I change the value of the textfield and select a new line that the event of selecting the new line overrides the text field System;

How could I define that the event of losing the textfield focus will always run before the tableView Listener?

Event that controls the focus of the text field, when exiting the field it changes the values in the tableView:

txtValorVenda.focusedProperty().addListener(new ChangeListener<Boolean>() {
    @Override
    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue,
            Boolean newPropertyValue) {

        if (!newPropertyValue) {
            if (!btnInsert.isPressed() && !btnClose.isPressed() && !btnCancel.isPressed()){

                tbViewPrecosEmp.getSelectionModel().getSelectedItem().setVlrVendaVarejo(Util.decimalBRtoBigDecimal(2,txtValorVenda.getText()));
                tbViewPrecosEmp.refresh();


            }
        }
    }
});

Event that controls the selection of an item in the tableView. When a row is selected, load the values of the tableView into the corresponding textfields:

tbViewPrecosEmp.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
    if (newSelection != null) {
        // CARREGA OS DADOS DA LINHA SELECIONADA OBJETO INSTANCIADO
            txtCusto.setText(tbViewPrecosEmp.getSelectionModel().getSelectedItem().getVlrCusto().toString());
            txtMargem.setText(tbViewPrecosEmp.getSelectionModel().getSelectedItem().getMargemLucroVarejo().toString());
            txtValorVenda.setText(tbViewPrecosEmp.getSelectionModel().getSelectedItem().getVlrVendaVarejo().toString());
    }
});

The problem is when the user fills a new value in textField, and clicks on a new selection in the tableView with this the tableview event executes before the one of the lost focus of the text field.

  • You can add snippets corresponding to both events?

  • Add the code snippet

  • Add the excerpt, someone has some idea of how to solve ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.