Reputation: 33
I have a small problem, When i want add textField, button and label to VBOX i have a error : addAll() in ObservableList cannot be applied to:
in this place: vBox.getChildren().addAll(textField, button, label);
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane layout = new BorderPane();
Scene scene = new Scene(layout, 400, 200);
TextField textField = new TextField();
Label label = new Label("Average: 0.0");
Button button = new Button("Przycisk");
button.setOnAction(event -> {
String textFromTextField = textField.getText();
String[] splittedText = textFromTextField.split(",");
double average = 0.0;
for (String s: splittedText) {
average += Double.parseDouble(s);
}
average /= splittedText.length;
label.setText("Average: " + average);
});
VBox vBox = new VBox();
vBox.getChildren().addAll(textField, button, label);
vBox.setAlignment(Pos.CENTER);
vBox.setSpacing(10);
layout.setCenter(vBox);
primaryStage.setScene(scene);
primaryStage.setTitle("App");
primaryStage.show();
}
}
Upvotes: 0
Views: 3786
Reputation: 1918
Take a good look at your imports!
In the image you can see that you used the TextField and Label from the 'awt' library instead of the 'javafx' library. Make sure to change that and see if it worked out!
(Ps. Please post the full stacktrace in your question next time!)
Upvotes: 0
Reputation: 937
That's because you have imported AWT components java.awt.Label
and java.awt.TextField
instead of JavaFX components javafx.scene.control.Label
and javafx.scene.control.TextField
.
Upvotes: 2