我正在努力实现这一目标,但遇到了一些问题。我得到了大致的骨架,但是例如,当我尝试将输出TextArea添加到我的Vbox容器中时,出现错误。
错误是:The method addAll(int, Collection<? extends Node>) in the type List<Node> is not applicable for the arguments (HBox, HBox, HBox, Button, TextArea)
编辑:我为TextArea输入了错误的内容,我使用awt而不是javafx.scene.control.TextArea;
GridPane g1 = new GridPane();
HBox firstRow = new HBox();
firstRow.setPadding(new Insets(10));
Label name = new Label("Name: ");
TextField nameInput = new TextField();
g1.add(name, 0, 0);
g1.add(nameInput, 1, 0);
firstRow.getChildren().addAll(g1);
GridPane g2 = new GridPane();
HBox secondRow = new HBox();
secondRow.setPadding(new Insets(10));
Label city = new Label("City: ");
TextField cityInput = new TextField();
g2.add(city, 0, 0);
g2.add(cityInput, 1, 0);
secondRow.getChildren().addAll(g2);
HBox thirdRow = new HBox();
thirdRow.setSpacing(20);
thirdRow.setPadding(new Insets(5));
RadioButton radioName = new RadioButton("Name");
RadioButton radioCity = new RadioButton("City");
RadioButton radioZip = new RadioButton("Zip");
ToggleGroup group = new ToggleGroup();
radioName.setToggleGroup(group);
radioCity.setToggleGroup(group);
radioZip.setToggleGroup(group);
thirdRow.getChildren().addAll(radioName, radioCity, radioZip);
Button search = new Button("Search");
HBox fifthRow = new HBox();
TextArea output = new TextArea();
VBox container = new VBox();
container.getChildren().addAll(firstRow, secondRow, thirdRow, search);
答案 0 :(得分:1)
您的问题最初并不太清楚,因为您没有包括看到的错误。问题是因为您导入了错误的TextArea
,而您的问题中也没有包含这些导入语句。
您需要将import java.awt.TextArea;
更改为import javafx.scene.control.TextArea;
。前者是AWT的控件,而后者是JavaFX的控件。
答案 1 :(得分:0)
如前所述,您需要将一个子“输出”(即TextBox元素)添加到容器中。
container.getChildren().addAll(firstRow, secondRow, thirdRow, search, output);
Aslo我想指出,您需要按正确的顺序排列元素,因为此代码根本不实用。