I have a TextField within a GridPane that I simply want to have it's user-typed contents read into an Integer that I will then use for multiple (non-double) calculations.
TextField userInput = new TextField(); userInput.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { if (!newValue.matches("\\d*")) { userInput.setText(newValue.replaceAll("[^\\d]", "")); } }); sortButton.setOnMousePressed( e -> { int savedValue = Integer.parseInt(userInput); int outputMath = savedValue * 3; int outputExpo = savedValue * 10; int outputQuad = savedValue * 4; }); The listener does a great job of making sure nothing but numbers gets accepted, but those numbers are read as a string that I don't seem able to use for calculations.
The problem child is that the Integer.parseInt(userInput) just doesn't seem to do the trick here. Any advice?