首页 > 解决方案 > JavaFX Layout complie time

问题描述

I'm trying to achieve this but I'm running into some problems. I got the rough skeleton, but for example when I try to add the output TextArea to my Vbox container, I get an error.

The error is: The method addAll(int, Collection<? extends Node>) in the type List<Node> is not applicable for the arguments (HBox, HBox, HBox, Button, TextArea)

EDIT: I had the wrong import for the TextArea, I had the awt instead of the 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);

标签: javafx

解决方案


Your question wasn't too clear initially because you did not include the error you saw. The problem is because you have imported the wrong TextArea, which import statements are also not included in your question.

You need to change import java.awt.TextArea; into import javafx.scene.control.TextArea;. The former is a control for AWT, while the latter is the control for JavaFX.


推荐阅读