Skip to content

Commit

Permalink
Added text input prevention for number input fields in StartView
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikollai committed May 19, 2026
1 parent 3f6b4ff commit 2ea3eee
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/millions/view/StartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
Expand Down Expand Up @@ -37,11 +38,23 @@ public StartView(Stage stage) {
startingAmountField
.textProperty()
.addListener((obs, oldVal, newVal) -> checkStartButtonValid());
startingAmountField.setTextFormatter(new TextFormatter<>(change -> {
if (change.getControlNewText().matches("([0-9]*)?")) {
return change;
}
return null;
}));
// Pre run weeks to run simulated weeks before the player starts
preRunWeeksField = new TextField("12");
preRunWeeksField.setPromptText("Pre run weeks:");
preRunWeeksField.setMaxWidth(250);
preRunWeeksField.textProperty().addListener((obs, oldVal, newVal) -> checkStartButtonValid());
preRunWeeksField.setTextFormatter(new TextFormatter<>(change -> {
if (change.getControlNewText().matches("([0-9]*)?")) {
return change;
}
return null;
}));

filepickerButton = new Button();
filepickerButton.setText("Pick file");
Expand Down

0 comments on commit 2ea3eee

Please sign in to comment.