我的代码:使用JavaFX-无法添加全部(文本字段,文本区域,字符串)。我不应该能够吗?
public class Main extends Application {
TextArea area = new TextArea();
TextField field = new TextField();
String text = "";
public void start(Stage primaryStage){
VBox pane = new VBox();
Button next = new Button("Next");
next.setOnAction(e->{
text+= "\n" + field.getText();
area.setText(text);
});
pane.getChildren().addAll(area,field,next);
Scene scene = new Scene(pane, 700, 300);
primaryStage.setTitle("CosmicWimpout");
primaryStage.setScene(scene);
primaryStage.show();
}
的错误是在.addAll
,错误写着:
The method addAll(int, Collection<? extends Node>) in the type List<Node> is not applicable for the arguments (TextArea, TextField, String).
所以,我只是编辑我的帖子,包括.addAll(区,场,旁边)。这些都是GUI节点,但the.addAll方法不接受这些参数。
在向VBox添加String时,你会发生什么?它只接受'节点'。 – Itai
编辑后使用的代码是一个按钮节点。仍然是一个问题。 –
这应该工作。你可以创建一个[mcve](http://stackoverflow.com/help/mcve)并更新你的问题来包含它吗?这可能是导入错误导致的错误。 – Itai