JavaFx numberbind和TextField

时间:2015-04-18 14:45:15

标签: javafx

我想从totalAmount

中减去变量IntegerBind TextField和值{}

我知道这种语法无效,因为它们与解析TextFieldIntegerBind标识符不兼容。

int parseReceivedCash = Integer.parseInt(receivedCashTextField.getText());

if((parseReceivedCash - alltotal))
{
  Alert alert = new Alert(Alert.AlertType.INFORMATION);
  alert.setHeaderText("Not Enough Cas");
  alert.setContentText("Sorry not enough cash"  );
  alert.showAndWait();
}


alltotal = Bindings.createIntegerBinding(() -> 
    tableData.getItems().stream().collect(Collectors.summingInt(Data::getSubTotal)),
    tableData.getItems());

1 个答案:

答案 0 :(得分:0)

有些事情:

IntegerProperty receivedCash = new SimpleIntegerProperty();
receivedCashTextField.textProperty().bindBidirectional(receivedCash, new NumberStringConverter());
IntegerBinding remainingAmount = allTotal.subtract(receivedCash);

remainingAmount.addListener(...); // check if amount is enough, etc...

应该提供您正在寻找的功能