I am attempting to create multiple JavaFX applications and have had no issues until now when I attempt to add a TextField
. I can have a brand new file and include a single line initializing a TextField
and it will cause the exceptions. I have looked all over online and got nothing. Simply adding the TextField causes the exceptions to appear even in other, previously running,k programs. Examples below:
The program I have created so far:
public class CH16Q04 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
VBox masterPane = new VBox();
HBox milesPane = new HBox();
HBox kiloPane = new HBox();
javafx.scene.control.TextField milesTF = new TextField("Miles: ");
milesTF.setAlignment(Pos.BASELINE_RIGHT);
javafx.scene.control.TextField kiloTF = new TextField("Kilometers" );
kiloTF.setAlignment(Pos.BASELINE_RIGHT);
milesPane.getChildren().addAll(new Label("Miles: "), milesTF);
kiloPane.getChildren().addAll(new Label("Kilometers: "), kiloTF);
masterPane.getChildren().addAll(milesPane,kiloPane);
BigDecimal milesInput = new BigDecimal(milesTF.getText());
BigDecimal kiloInput = new BigDecimal(kiloTF.getText());
milesTF.setOnAction(e -> {
kiloTF.setText((milesInput.multiply(new
BigDecimal("1.609344")).toString()));
kiloTF.setStyle("-fx-text-fill: red");
});
kiloTF.setOnAction(e -> {
milesTF.setText(kiloInput.multiply(new
BigDecimal("0.621371")).toString());
milesTF.setStyle("-fx-text-fill: red");
});
Scene scene = new Scene(masterPane);
primaryStage.setTitle("Chapter 16, Question 04");
primaryStage.setScene(scene);
primaryStage.show();
}
}