我有一個小問題,當我想添加文本框, 按鈕和標籤到VBOX我有一個錯誤: 中的addAll()在ObservableList不能適用於:JavaFX的VBox中的getChildren()中的addAll()錯誤
在這個地方: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();
}
}